What's new

DirectDraw in C

bcrew1375

New member
I've been trying for a while to get a simple DirectDraw program written in C to compile under MSVC++ 6.0. It refuses to compile this line:

Code:
DirectDrawCreateEx(NULL, &lpDD, IID_IDirectDraw7, NULL);

It gives me the following errors:

Code:
directdraw.c(5) : error C2115: 'function' : incompatible types
directdraw.c(5) : warning C4024: 'DirectDrawCreateEx' : different types for formal and actual parameter 3

Any ideas?

BTW, I've included ddraw.h, and I've added the ddraw.lib and dxguid.lib files.
 

smcd

Active member
I googled for "warning C4024: 'DirectDrawCreateEx' : different types for formal and actual parameter 3" without the quotes and got 2 results, both from gamedev.net, and both saying the below. Give it a try ;)

http://www.gamedev.net/community/forums/topic.asp?topic_id=34452
http://www.gamedev.net/community/forums/topic.asp?topic_id=85221

DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL); should be changed to:

DirectDrawCreateEx(NULL, (VOID**)&lpDD, &IID_IDirectDraw7, NULL);
 
OP
B

bcrew1375

New member
Thanks, seth. That is weird though. I swear to you I found both of the pages you just linked before, I tried exactly what they said and it refused to work. Yet when you suggested it just now and I tried it, it magically works. What's the deal o_O?
 

blueshogun96

A lowdown dirty shame
Yeah, your problem was the fact that you didn't have a '&' in front of your GUID. I forgot why, but when you are using COM in C, you need to do that for EVERY GUID you use, not just with DirectDrawCreateEx, but also with IUnknown::QueryInterface. I am a die-hard, strait C, DirectDraw programmer myself, so I have had my fair share of this.
 

Poobah

New member
Would someone be able to post a guide of some sort that explains how to actually use Directdraw in C?
 
OP
B

bcrew1375

New member
I've looked for a guide, but I have yet to find one. For the functions I've used so far, I had to make the pointer in front of the function the first argument in the parentheses and then add "IDirectDraw7_" where the pointer was.

So, as far as I can tell:

Code:
lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);

Would become something like this in C:

Code:
IDirectDraw7_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
 

ShizZy

Emulator Developer
Because some people like C better, there needs no explanation further than that ;)

Personally, I like to use C in a C++ programming enviroment. (By taking advantage of things like variable declarations at various points in a function, C++ libs, and on a rare occasion namespaces). For the most part though, my code is pretty straight C. Too many classes and such generally leads to fluff in my opinion, at least for emulator programming. (There is use else where though).
 

Poobah

New member
bcrew1375 said:
I've looked for a guide, but I have yet to find one. For the functions I've used so far, I had to make the pointer in front of the function the first argument in the parentheses and then add "IDirectDraw7_" where the pointer was.

So, as far as I can tell:

Code:
lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
Would become something like this in C:

Code:
IDirectDraw7_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);

I see, thanks for that.:nuke:Now I just have to be disciplined enough to make myself memorise all the important function names and constants.:(
 

blueshogun96

A lowdown dirty shame
also, you can do this. Its what I prefer:

Code:
lpDD->lpVtbl->SetCooperativeLevel( lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE );

that goes for all versions of DirectDraw and DirectX in general.
 

Poobah

New member
blueshogun96 said:
also, you can do this. Its what I prefer:

Code:
lpDD->lpVtbl->SetCooperativeLevel( lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE );
that goes for all versions of DirectDraw and DirectX in general.

I thought you could only use functions within structures/classes in C++?
 

blueshogun96

A lowdown dirty shame
Well, actually you can call functions inside of structs in C, you just have to setup a function pointer.

Also, remember that DirectX does NOT use classes. It uses COM interfaces. They are slightly different than classes and structures, but cool to use. And if you look at ddraw.h you will see that IDirectDraw7_SetCooperativeLevel is not really a function definition, but a macro definition. It's just an easy way to write code that is compatible with both C and C++ so that you dont have to add/delete the lpVtbl. The lpVtbl is whats called the Vtable. Since C does not support this pointers, thats why you have to pass in the pointer to the interface pointer you are using.

EDIT:
Drug Free For Life: 98% of the teenage population has
tried drugs at least once. If you are one of the 2%
who hasn't, copy and paste this into your signature.
I'm not a teenager, but I have never done/tried drugs before in my entire life either :)
 
OP
B

bcrew1375

New member
Does anyone happen to know where I could find a list of DirectDraw functions, their arguments, and what they do?
 

blueshogun96

A lowdown dirty shame
bcrew1375 said:
Does anyone happen to know where I could find a list of DirectDraw functions, their arguments, and what they do?
Yeah, I can give you a help file from my dx7 sdk. Hold on a little while... I dont have access to it atm, because I'm at a public computer.
 
Last edited:

Top