Handmade Hero»Forums»Code
306 posts / 1 project
None
DirectX header files
In a fairly recent episode (two-hundred something) Casey briefly mentioned during Q&A that in his project at Molly Rocket he is not including any header files for using DirectX. Can someone explain how this is possible? Maybe I just misunderstood his statement?

Thanks much.
Marc Costa
65 posts
DirectX header files
Casey said that he uses OpenGL at Molly Rocket, and he loads the OpenGL functions himself from the DLL.

He doesn't use header DirectX header files because he doesn't use DirectX.
Mārtiņš Možeiko
2559 posts / 2 projects
DirectX header files
Edited by Mārtiņš Možeiko on
I'm pretty sure he simply defines structures/constants himself and declares function pointers to needed functions (that are loaded with GetProcAddress). This applies to regular Windows symbols as well as for OpenGL and DirectX.

For example, if you want to use "Sleep" function, then you do this:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
typedef void VOID;
typedef unsigned int DWORD;
#define WINAPI __stdcall

VOID (*WINAPI Sleep)(DWORD dwMilliseconds);

...
// somehwhere in initialization code
Sleep = (VOID (*WINAPI)(DWORD))GetProcAddress(kernel32, "Sleep");

...
// somehwere where you want to use it
Sleep(100);

Of course you can improve all that crazy function pointer casts with helper macros, same as on HandmadeHero stream.

You only need to link to kernel32.dll file to get GetProcAddress un GetModuleHandle functions.
306 posts / 1 project
None
DirectX header files
I understand how to retrieve function ptrs to the Win32 API. However, if you are using DirectX, and maybe Casey is not based on marcc's answer, then you would have to know interface definitions, GUIDs, etc. none of which are part of a DLL's exports.
Mārtiņš Možeiko
2559 posts / 2 projects
DirectX header files
Edited by Mārtiņš Možeiko on
Yes you have. You either copy them from MSDN or from official headers into your code.
306 posts / 1 project
None
DirectX header files
Makes sense. I missed the copy-n-paste from official headers into your codebase to avoid #include'ing things you may not want/need. Thanks much mmozeiko.