You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何使用PVOID定义_tWinMain会触发类型冲突错误?

关于使用PVOID定义_tWinMain出现类型冲突的问题

问题背景

根据微软文档,HINSTANCE的定义如下:

typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;

但当我尝试用PVOID定义_tWinMain时,却出现了类型冲突错误,我的代码如下:

int WINAPI
_tWinMain (PVOID hInstance, PVOID hPrevInstance, PTSTR pCmdLine, int nShowCmd)

报错信息

gcc编译时抛出错误:

error: conflicting types for 'WinMain'; have 'int(void *, void *, CHAR *, int)' {aka 'int(void *, void *, char *, int)'}
   64 | _tWinMain (PVOID hInstance, PVOID hPrevInstance, PTSTR pCmdLine, int nShowCmd)
      | ^~~~~~~~~

同时编译器提示头文件中已有WinMain的声明,类型不匹配:

mingw64\x86_64-w64-mingw32\include\winbase.h:1111:14: note: previous declaration of 'WinMain' with type 'int(struct HINSTANCE__ *, struct HINSTANCE__ *, CHAR *, int)' {aka 'int(struct 
HINSTANCE__ *, struct HINSTANCE__ *, char *, int)'}
 1111 |   int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
      |              ^~~~~~~

环境说明

运行环境为Windows 10(64位),使用winlibs 11.2中的mingw编译器。另外,在我的winlibs路径mingw64\x86_64-w64-mingw32\include\wtypes.h中,HINSTANCE的实际定义是:

typedef void *HINSTANCE;

解决方法

添加#define NO_STRICT禁用STRICT标志后,问题得到解决。


内容的提问来源于stack exchange,提问作者jinreal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 03:00:55