[英]What is the correct way to define a UNICODE independent WinMain function?
為使用CRT的Windows程序定義獨立於UNICODE
WinMain
函數的正確方法是什么?
我傾向於認為它應該像
WINAPI
#ifdef UNICODE
wWinMain
#else
WinMain
#endif
( ... ) {
...
}
但是,我想知道在編譯源單元時是否還沒有預定義的宏可以擴展為正確的符號(如Windows頭文件中提供的擴展為WinApiFuncA
或WinApiFuncW
。
在<tchar.h>
,宏_tWinMain
會根據項目設置擴展為WinMain
或wWinMain
。 但是,這還不夠。 您還需要lpCmdLine
與字符集無關的LPTSTR
聲明第三個參數( lpCmdLine
):
int APIENTRY _tWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nShowCmd
)
如果在項目上啟用了Unicode, LPWSTR
變成LPWSTR
,並提供簽名:
int APIENTRY wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd
)
如果未啟用Unicode,則會獲得簽名:
int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.