error LNK2019, LNK1120 : win32 API programing by vc++2005 beta2

i am beginer in c++.
i wanna learn win32api. 
so, i tried below example
using vc++2005 express beta2.
but i met following 2 errors :
Error 1 error LNK2019: unresolved external symbol _main 
        referenced in function _mainCRTStartup MSVCRTD.lib
Error 2 fatal error LNK1120: 1 unresolved
       externals c:\test\parse\winapitest3\winapitest3
       \Debug\winapitest3.exe 
//--------------------------------------------------------------

here, my example code:

#include <windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="test";//"First";

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE 
           hPrevInstance ,LPSTR lpszCmdParam,int nCmdShow)
{
 HWND hWnd;
 MSG Message;
 WNDCLASS WndClass;
 g_hInst=hInstance;
 
 WndClass.cbClsExtra=0;
 WndClass.cbWndExtra=0;
 WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
 WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
 WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 WndClass.hInstance=hInstance;
 WndClass.lpfnWndProc=(WNDPROC)WndProc;
 //WndClass.lpszClassName=(LPCWSTR)lpszClass;
 WndClass.lpszClassName=lpszClass;
 WndClass.lpszMenuName=NULL;
 WndClass.style=CS_HREDRAW | CS_VREDRAW;
 RegisterClass(&WndClass);

 hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
    NULL,
    (HMENU)NULL,
    hInstance,
    NULL);
    //(LPCWSTR)NULL);
 ShowWindow(hWnd,nCmdShow);
 
 while(GetMessage(&Message,0,0,0)) {
  TranslateMessage(&Message);
  DispatchMessage(&Message);
 }
 return Message.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
 switch(iMessage) {
 case WM_DESTROY:
  PostQuitMessage(0);
  return 0;
 }
 return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
//----------------------------------------





Answer this question

error LNK2019, LNK1120 : win32 API programing by vc++2005 beta2

  • Rasmus Helmsby Sandberg

    THANK YOU!!!
    exactly solved. 

    have a nice day :)

  • galic

    Is it possible that the linker options are set to /SUBSYSTEM:CONSOLE The linker will search for an entry point main. If you define /SUBSYSTEM:WINDOWS WinMain will be used as an entry point.

  • Xaz

    For Visual Net (and other versions...I hope)

    Project/ Propertys....Folder "Linker"/Additional Dependencies/ HERE!!!...You add additional *.lib which you are needing because of you are using additional librarys.

    Example: I usually need OpenCV. I have to include into here: cv.lib cxcore.lib highgui.lib cvcam.lib.


  • Guillaume JAY

    Actually, the linker searches for mainCRTStartup, which is a wrapper around a call to main.  Similarly, WinMainCRTStartup wraps WinMain.
  • error LNK2019, LNK1120 : win32 API programing by vc++2005 beta2