INITGUID: An Explanation

Started by
2 comments, last by RWarden 23 years, 9 months ago
A lot of people (especially newbies) have this problem with DirectX. Here''s the deal: you have all your libraries set up and included in your program, yet you still get linkers errors for things like IID_IDirectDrawSurface7. To fix these errors, you need to #define INITGUID somewhere in your project. It must be defined before you include all the DirectX header files, and it must be defined only once per project (or you''ll get redefinition linker errors). The main source file is a good place to put this definition. However, you can run into problems when using pre-compiled headers. Let''s say you have one header file, precomp.h, that includes all of the Windows/DirectX header files. This pre-compiled header is included by every source file in your project and created through a file called precomp.cpp. Where do you put the INITGUID definition? Well, the first obvious place is either in precomp.h or precomp.cpp (which evaluates to exactly the same thing). However, if you do this, it will result in INITGUID being re-defined for every source file that uses the PCH. This can easily create thousands and thousands of linker errors. The second place would be in one of your source files, before you include the PCH. However, this won''t work either, because pre-compiled headers are pre-compiled and thus aren''t affected by #defines and such in the files they are included in. Putting #define INITGUID in a source file using a PCH will have no effect at all (and thus, you''ll have linker errors). The solution? It''s kind of a hack, and maybe there''s a better way (if you know of one, please let me know ). Create a new file for your project, name it initguid.cpp. Inside that file, #define INITGUID, then include all the DirectX header files. Do not set this file to use a pre-compiled header. Yes, you could simply #define INITGUID in any source file and make sure that source file doesn''t use your PCH (includes precomp.h without being set to use a precompiled header), but this would kind of defeat the purpose of having the PCH. Your initguid.cpp file will only be compiled once, and during full project rebuilds, and will fix all those damn linker errors. Hope that helps everyone who''s having trouble with that fun little aspect of DirectDraw . -RWarden (roberte@maui.net)
Advertisement
It is much easier NOT to define INITGUID.

Just add dxguid.lib to the list of libraries to link with.
(Hits self in head)

I developed that while working in DirectX 3, before dxguid.lib. And now I feel stupid.. =)

-RWarden (roberte@maui.net)
Is that why #define INIT_GUID is barely mentioned in any docs?

-Magmai Kai Holmlor

I am brazen and fear no flames.
(So long as I don't lose this Ring of Fire Protection +5)
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement