c++winapihinstance

Forward declare HINSTANCE and friends


Is there a way to forward-declare the HINSTANCE type from the WinAPI without including the full (and big) windows.h header?

For example, if I have a class RenderWindow which owns an HINSTANCE mInstance, i will have to include windows.h in RenderWindow.h. So everything that needs RenderWindow also has to include windows.h.

I tried including windef.h but this seems to need some things from windows.h. :-( If I can't forward declare it, is there at least a portable way to use something like long mInstance in RenderWindow instead of HINSTANCE?


Solution

  • HINSTANCE is declared in WinDef.h as typedef HINSTANCE__* HINSTANCE;

    You may write in your headers:

    #ifndef _WINDEF_
    class HINSTANCE__; // Forward or never
    typedef HINSTANCE__* HINSTANCE;
    #endif
    

    You will get compilation errors referencing a HINSTANCE when WinDef.h is not included.