-
IID_IDirectDraw7
Hello. I am having a problem with using DirectDraw. When I use the CreateWindow() function, in VC++.NET Pro, the linker sees IID_IDirectDraw7 as an unresolved external symbol in my code but if I compile the examples by Andre LaMothe, everything works fine.
Code:
DirectDrawCreateEx(NULL,(void **)&lpdd,IID_IDirectDraw7, NULL)
I attached my .cpp file with the code.
*edit* I always forget that third I in IID_IDirectDraw7
-
You should link your program with dxguid.lib
-
Thanks!! but why would it compile if i used LaMothe's cpp file in my project b/c dxguid.lib wasn't included then either?
-
If I remember correctly, he uses a macro called INITGUID
#define INITGUID
before all included files. That way dxguid.lib isn't needed, the guids are defined in the .h files.
-
OK, that makes sense. Thanks for the help.
-
I have another problem. When usinf ddutil.h and .cpp I load a bitmap and when it displays i get a lot of jumbled image behind the image i am displaying. I attached the project it is in a VC++.NET solution.
*edit* attached the wrong files
-
Code:
//Global variable
DDSURFACEDESC2 ddsd;
//SetupSurface() definition
SetupSurface(DDSURFACEDESC2 ddsd)
{
//...
}
//In GameInit()
SetupSurface(ddsd);
You're trying to use SetupSurface() to:
a) Fill in the global variable ddsd and create a primary surface with it
b) Later, use the global variable ddsd to load a bitmap
The problem is:
SetupSurface() takes a DDSURFACEDESC2 struct, not a pointer to a DDSURFACEDESC2 struct, and since the parameter ddsd has the same name as the global variable ddsd, it will fill in the parameter ddsd, create the primary surface, then the filled-in ddsd goes out of scope and is destroyed, leaving the un-filled global ddsd to be passed to the DDLoadBitmap() function. There are 4 possible solutions:
1) Change the arguments for SetupSurface() to a DDSURFACEDESC2 reference
2) Change the name of the argument to "useless" or something, since it isn't needed (the function accesses the global variable directly), and/or delete it.
3) Instead of simply calling SetupSurface(ddsd), do:
ddsd = SetupSurface(ddsd);
4) Something I haven't thought of ;)
**EDIT**
BTW, you should probably take option 1 or 2, as option 3 is somewhat... inefficient and hard to read, and *might* not work. And for option 2, you probably should just get rid of the argument.
*And just as a side note, I find it easier to keep track of where each bit of code is if I keep all function definitions to .cpp files.
-
Thanks I'm going to try that now.
-
Yes, I tried both options 1 and 2 and it still had the junk behind it so then i tried compling example 2 from sunlight's tutorials and they too had the stuff behind it so I guess I have to figre out why this is happening b/c things I don't compile look great.
-
Ahh oops, I read your code wrong :( I thought you were passing ddsd to DDLoadBitmap, but you were passing lpdd instead. Any information I previously posted is now void, and any harm it may have done to your application is not my fault ;)
-
Wow!!! thats good to hear b/c I tohught that I had just gone stupid, but luckily I have gone stupid but my code is still correct!!! Well I seem to be having more luck with DirectDraw in C# b/c notihng I can think of is making it work with C++. Maybe M$ just doesn't like me.:(
-
Hmm... well, I don't know, I didnt look at all your code, I only took a glance at it and pointed out some (wrong) problems that I saw. If you want, you can take a look at the DirectDraw code that I made just a little while ago for my game. It might be a little hard to understand (because of the lack of comments), but it works.
Setting up and loading/drawing bitmaps is all wrapped up in a few easier-to-use functions, and if you look at the code, it might help with your problem (or on the other hand, it might just confuse you more :D), or if you really want you could just adapt the class to your purpose, although that isn't recommended ;)
**EDIT**
P.S. There's a lot of things that aren't done too well in my code, just so you know and don't think it's perfect ;)