LNK2019错误,怀疑是设置错误

kevinnick 2009-02-09 03:44:06
错误 2 error LNK2019: unresolved external symbol "long __stdcall MainWndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MainWndProc@@YGJPAUHWND__@@IIJ@Z) referenced in function "int __cdecl InitApplication(struct HINSTANCE__ *)" (?InitApplication@@YAHPAUHINSTANCE__@@@Z) test.obj



#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#pragma comment(lib,"Winmm.lib")

// Global variable

HINSTANCE hinst;

// Function prototypes.

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
BOOL InitApplication(HINSTANCE hinstance);
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

// Application entry point.

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;

if (!InitApplication(hinstance))
return FALSE;

if (!InitInstance(hinstance, nCmdShow))
return FALSE;

BOOL fGotMessage;
while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0 && fGotMessage != -1)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
UNREFERENCED_PARAMETER(lpCmdLine);
}

BOOL InitApplication(HINSTANCE hinstance)
{
WNDCLASSEX wcx;

// Fill in the window class structure with parameters
// that describe the main window.

wcx.cbSize = sizeof(wcx); // size of structure
wcx.style = CS_HREDRAW |
CS_VREDRAW; // redraw if size changes
wcx.lpfnWndProc = MainWndProc; // points to window procedure
wcx.cbClsExtra = 0; // no extra class memory
wcx.cbWndExtra = 0; // no extra window memory
wcx.hInstance = hinstance; // handle to instance
wcx.hIcon = LoadIcon(NULL,
IDI_APPLICATION); // predefined app. icon
wcx.hCursor = LoadCursor(NULL,
IDC_ARROW); // predefined arrow
wcx.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); // white background brush
wcx.lpszMenuName = TEXT("MainMenu"); // name of menu resource
wcx.lpszClassName = TEXT("MainWClass"); // name of window class
wcx.hIconSm = (HICON)LoadImage(hinstance, // small class icon
MAKEINTRESOURCE(5),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR);

// Register the window class.

return RegisterClassEx(&wcx);
}

BOOL InitInstance(HINSTANCE hinstance, int nCmdShow)
{
HWND hwnd;

// Save the application-instance handle.

hinst = hinstance;

// Create the main window.

hwnd = CreateWindowW(
TEXT("MainWClass"), // name of window class
TEXT("Sample"), // title-bar string
WS_OVERLAPPEDWINDOW, // top-level window
CW_USEDEFAULT, // default horizontal position
CW_USEDEFAULT, // default vertical position
CW_USEDEFAULT, // default width
CW_USEDEFAULT, // default height
(HWND) NULL, // no owner window
(HMENU) NULL, // use class menu
hinstance, // handle to application instance
NULL); // no window-creation data

if (!hwnd)
return FALSE;

// Show the window and send a WM_PAINT message to the window
// procedure.

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return TRUE;

}



从MSDN上面 复制的一段代码,稍微修改了一下,但是提示 LNK2019错误,google了一下没有看到,怀疑是设置的问题,各位老大帮忙看看!
...全文
114 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lgccaa 2009-02-09
  • 打赏
  • 举报
回复
尽信书不如无书,书只是参考,动手了才知道怎么回事
kevinnick 2009-02-09
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/en-us/library/ms633575(VS.85).aspx

就是从这儿复制的!!!
kevinnick 2009-02-09
  • 打赏
  • 举报
回复
哈,该来该去终于对了!

吗的,MSDN也太不负责了,程序中还有一个函数没有定义就贴上去了,
再也不那么相信他们了..........
biweilun 2009-02-09
  • 打赏
  • 举报
回复
加上代码后,是什么错误信息?
biweilun 2009-02-09
  • 打赏
  • 举报
回复
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
MainWndProc这个回调函数没有进行定义,要在下面写相应代码,你只有个申明当然不行
kevinnick 2009-02-09
  • 打赏
  • 举报
回复
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;

switch (message)
{
case WM_CREATE:

PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
MessageBoxW (NULL, TEXT ("下面,将显示一个由我\n新建的窗口---_The Hello Program!"), TEXT ("message_window"), 0|1|2);
return 0 ;

case WM_PAINT:

hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello, Windows server 2003 \n Enterprise Edition!"), -1, &rect,
/*DT_SINGLELINE | DT_CENTER | DT_VCENTER*/DT_CENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;

case WM_DESTROY:

PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}


加上这段还是不对,各位老大帮忙看看!!!
hhyttppd 2009-02-09
  • 打赏
  • 举报
回复
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM); //这个函数没定义。。。
kevinnick 2009-02-09
  • 打赏
  • 举报
回复
哦,掉了一段!晕!

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧