本文介绍了转发声明HINSTANCE和朋友的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从WinAPI转发声明 HINSTANCE 类型,而不包括完整(和大) windows.h header

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

例如,如果我有一个类 RenderWindow c> HINSTANCE mInstance ,我必须在中包含 windows.h RenderWindow.h 。因此,需要 RenderWindow 的所有内容也必须包括 windows.h

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.

我尝试包括 windef.h 但这似乎需要从 windows.h 的一些东西。 :-(如果我不能转发声明,是否至少有一个可移植的方法来使用 long mInstance RenderWindow 而不是 HINSTANCE

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?

推荐答案

HINSTANCE是在WinDef .h as typedef HINSTANCE __ * HINSTANCE;

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

您可以在标题中写下:

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

当不包括WinDef.h时,您会遇到引用HINSTANCE的编译错误。

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

这篇关于转发声明HINSTANCE和朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 09:33