View Full Version : DirectDraw in C
bcrew1375
May 9th, 2006, 04:15
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:
DirectDrawCreateEx(NULL, &lpDD, IID_IDirectDraw7, NULL);
It gives me the following errors:
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.
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);
bcrew1375
May 9th, 2006, 04:37
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?
Weird indeed, but glad it works now
blueshogun96
May 17th, 2006, 02:06
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
June 3rd, 2006, 06:02
Would someone be able to post a guide of some sort that explains how to actually use Directdraw in C?
bcrew1375
June 3rd, 2006, 06:59
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:
lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
Would become something like this in C:
IDirectDraw7_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
Doomulation
June 3rd, 2006, 12:29
One question though:
Why use C?
ShizZy
June 3rd, 2006, 19:48
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).
bcrew1375
June 3rd, 2006, 19:49
One question though:
Why use C?
For me, I just don't like C++. It has too many things that I don't need, and it is easier for me to use C.
Poobah
June 4th, 2006, 11:26
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:
lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
Would become something like this in C:
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
June 6th, 2006, 19:08
also, you can do this. Its what I prefer:
lpDD->lpVtbl->SetCooperativeLevel( lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE );
that goes for all versions of DirectDraw and DirectX in general.
Poobah
June 7th, 2006, 12:41
also, you can do this. Its what I prefer:
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
June 7th, 2006, 19:04
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 :)
bcrew1375
June 13th, 2006, 05:02
Does anyone happen to know where I could find a list of DirectDraw functions, their arguments, and what they do?
smcd
June 13th, 2006, 05:48
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/ddraw7/directdraw7/ddover_7dx3.asp
Outside of that, if you can find some of the older DirectX and/or platform SDK there should be browseable documentation there as well.
blueshogun96
June 15th, 2006, 23:50
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.
bcrew1375
June 16th, 2006, 06:55
Thanks, seth, blueshogun.
blueshogun96
June 23rd, 2006, 19:37
Thanks, seth, blueshogun.
Yo, sorry it took so long, I completely forgot about it :( Anyway, here it is.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.