Archived

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

Program errors...

This topic is 5582 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

I downloaded this tutorial off of Subduck.com and when I compiled it, it compiled. When I executed it, I was asked to build it. I built it but I recieved the following error: --------------------Configuration: Main - Win32 Debug----------- Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/Main.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. Main.exe - 2 error(s), 0 warning(s) Anyone know what''s wrong? Here is the source code: #include <windows.h> // Message Handling Procedure LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_DESTROY: { // Send a WM_QUIT message, as we want the app to exit once the window is destroyed PostQuitMessage(0); } break; } // Use the default message handler return DefWindowProc(hWnd, Msg, wParam, lParam); } // Windows Main function int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX WndClassEx; WndClassEx.cbSize = sizeof(WndClassEx); WndClassEx.cbClsExtra = 0; // No extra storage WndClassEx.cbWndExtra = 0; // No extra storage WndClassEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // White background WndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW); // Default arrow cursor WndClassEx.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Default app icon WndClassEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // Default app icon WndClassEx.hInstance = hInstance; // Application instance WndClassEx.lpfnWndProc = WndProc; // Message Procedure WndClassEx.lpszClassName = "Window Class"; // Class name WndClassEx.lpszMenuName = NULL; // No menu WndClassEx.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC; // Class styles // Register the window class so it can be used if (!RegisterClassEx(&WndClassEx)) { MessageBox(NULL, "Unable to register window class.", "Error", MB_ICONERROR); return 0; } // Create the window HWND hWnd = CreateWindowEx(NULL, "Window Class", "Window", WS_VISIBLE | WS_OVERLAPPEDWINDOW, 200, 200, 320, 240, NULL, NULL, hInstance, NULL); if (hWnd == NULL) { MessageBox(NULL, "Unable to create window.", "Error", MB_ICONERROR); return 0; } MSG Msg; // Mssage pump while (GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return 0; }

Share this post


Link to post
Share on other sites
The error is from the linker because it cannot find the function "main". This is most likely cause because you have created a console application.

Recreate your project and set it to be a "Windows Application" instead of a "Console Application".


If you look at the code you posted, you will see that there is a function called "WinMain". This is the windows version of "main"

Share this post


Link to post
Share on other sites
This is a very common problem (as you could see if you searched the forum).

You''ve set your project up as a Win32 Console application instead of a Win32 application.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
Now i'm recieving this message:




--------------------Configuration: Win - Win32 Debug------------
Compiling...
Win.cpp
c:\program files\microsoft visual studio\myprojects\win\win.cpp(62) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.

Win.obj - 1 error(s), 0 warning(s)




Any suggestions?


[edited by - wikedgamer on September 2, 2002 6:19:59 PM]

[edited by - wikedgamer on September 2, 2002 6:20:25 PM]

Share this post


Link to post
Share on other sites
in your project settings, under the header precompile directives, you can disable it.

or just make a file called stdafx.h
include windows.h in that file
and include stafx.h on the top of your file.

Its my duty, to please that booty ! - John Shaft

Share this post


Link to post
Share on other sites