Archived

This topic is now archived and is closed to further replies.

Win32 Linking error...

This topic is 5533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry to bug you all on this subject, but I got the program to compile, but when I go to link it, it says there are 2 errors. I''m really stuck any help would be appreciated. Thanks! (using MSVC++ 6.0) Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/WinMain.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. WinMain.exe - 2 error(s), 0 warning(s) code: #include <windows.h> // Function Prototypes int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd); LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; MSG Msg; WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC, WindowProc, 0L, 0L, hInstance, NULL, NULL, NULL, NULL, "GameClass", NULL }; // register the class and exit on error if(!RegisterClassEx(&wcex)) return FALSE; // Create the window (320x240 at 0,0 using overlapped style hWnd = CreateWindow("GameClass", "My Game Title", WS_OVERLAPPEDWINDOW, 320, 240, 0, 0, NULL, NULL, hInstance, NULL); // Return on error creating the window if(hWnd == NULL) return FALSE; // Show the Window ShowWindow(hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); // Clear out the message structure ZeroMemory(&Msg, sizeof(MSG)); // Loop endlessly until you receive a quit message while(Msg.message != WM_QUIT) { // Peek into the queue and see if there''s a message waiting if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) { // There''s a message! Handle it normally. TranslateMessage(&Msg); DispatchMessage(&Msg); } else { // No messages waiting,. Go ahead and do time-crucial // stuff here, such as rendering the game''s graphics } } // Unregister class UnregisterClass("GameClass", hInstance); // Exit application return 0; } // The message procedure LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); // Tell Windows to Close application break; // Handle every other message default: return DefWindowProc(hWnd, uMsg, wParam,lParam); } return 0; }

Share this post


Link to post
Share on other sites
You should have set the project up as a Win32 app, instead of a console app. It''s looking for "main" because that is the starting point for console apps. If you set it to a win32 app, it will look for "WinMain" which you have.

Share this post


Link to post
Share on other sites
Sounds like it''s looking for a console-app "main(...)" function.


Check out your project settings and if you find "Subsystem: Console" change it to "Windows"


I''m using VS.NET, and I can''t remember *exactly* where it is in 6.0, so you''ll hafta look for it.


I''m 90% sure this is your problem.

Share this post


Link to post
Share on other sites