c++ - 转发声明 HINSTANCE 和 friend

标签 c++ winapi hinstance

有没有一种方法可以从 WinAPI 中转发声明 HINSTANCE 类型,而不包括完整的(和大的)windows.h header ?

例如,如果我有一个拥有 HINSTANCE mInstance 的类 RenderWindow,我将必须在 中包含 windows.h >RenderWindow.h。所以所有需要 RenderWindow 的东西也必须包含 windows.h

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

最佳答案

HINSTANCE 在 WinDef.h 中声明为 typedef HINSTANCE__* HINSTANCE;

你可以在你的标题中写:

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

如果不包含 WinDef.h,您将遇到引用 HINSTANCE 的编译错误。

关于c++ - 转发声明 HINSTANCE 和 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2574549/

相关文章:

c++ - win32 hInstances 是唯一的吗?

c++ - 使用指针迭代数组元素

具有空对象模型的 C++ 双向链表

c++ - _i64toa_s 的等效项是什么?

c++ - JRTPLIB/header include问题

c++ - "hInstance"未定义。 C++ WIN32 APP

c++ - 互斥粒度

c++ - Win32 GetOpenFileName 阻止应用程序退出

c++ - Windows.h 宏未定义