Program errors...
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;
}
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"
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"
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
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
did you compile it as a win32 console app or as a win32 app. It should be compiled as a win32 app.
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]
--------------------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]
Disable precompiled headers in your project settings.
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement