在Dev-C ++中编译Windows程序会出错 [英] Compiling Windows program in Dev-C++ gives error
问题描述
我只是想学习用C ++编写Windows程序并使用Dev-C ++ IDE。我试图编译的第一个程序是从MSDN网站的以下示例:
I'm just learning to program Windows Programs in C++ and use the Dev-C++ IDE. The first program I'm trying to compile is the following example from the MSDN site:
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
// Run the message loop.
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
但是当我尝试编译它时,我得到以下错误:
But when I try to compile it I get the following error:
C:\Dev-Cpp \lib / libmingw32.a(main.o)(。text + 0x106):main.c:未定义引用`WinMain @ 16'
推荐答案
看起来像 mingw
运行时未正确配置为支持Unicode,因为您提供了Unicode wWinMain
,它正在寻找ANSI版本。
It looks like the mingw
runtime isn't correctly configured for Unicode support, because you've provided the Unicode wWinMain
and it's looking for the ANSI version.
您可以切换到Unicode中性编程(定义 _tWinMain
并使用 LPTSTR
,而不是 LPWSTR
,还要 _T(string)
,而不是 )。
You could switch to Unicode-neutral programming (define _tWinMain
and use LPTSTR
instead of LPWSTR
, also _T("string")
instead of L"string"
).
要做到这一点,你还必须 #include< tchar.h>
。
To do that, you must also #include <tchar.h>
.
这篇关于在Dev-C ++中编译Windows程序会出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!