ERROR!!!!!

when i compile this code i get an error. I got this code from a tutorial so i think it must be the program i am using to compile it. I tried Microsoft visual and borland and both of them dident word.

heres the code





#include <windows.h>

const char *ClsName = "BasicApp";
const char *WndName = "A Simple Window";

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;

// Create the application window
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClsName;
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

// Register the application
RegisterClassEx(&WndClsEx);

// Create the window object
hWnd = CreateWindow(ClsName,
WndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

// Find out if the window was created
if( !hWnd ) // If the window was not created,
return 0; // stop the application

// Display the window to the user
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

// Decode and treat the messages
// as long as the application is running
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

return Msg.wParam;
}

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
// If the user wants to close the application
case WM_DESTROY:
// then close it
PostQuitMessage(WM_QUIT);
break;
default:
// Process the left-over messages
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
// If something was not done, let it go
return 0;
}






------------------------------------
HERES THE ERROR MESSAGE!!!!!!!!!!!
WHAT IS THE PROBLEM????????????
------------------------------------


bcc32 -D_DEBUG -g100 -j25 -Od -r- -k -y -v -vi- -tWC -c -IC:\CBuilderX\include -o"C:\Documents and Settings\StealthOp1217\cbproject\ConsoleApp1\windows\Debug_Build\File1.obj" File1.cpp
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
File1.cpp:
"File1.cpp": W8057 Parameter 'hPrevInstance' is never used in function __stdcall WinMain(HINSTANCE__ *,HINSTANCE__ *,char *,int) at line 63
"File1.cpp": W8057 Parameter 'lpCmdLine' is never used in function __stdcall WinMain(HINSTANCE__ *,HINSTANCE__ *,char *,int) at line 63
"File1.cpp": W8057 Parameter 'nCmdShow' is never used in function __stdcall WinMain(HINSTANCE__ *,HINSTANCE__ *,char *,int) at line 63
ilink32 -D -ap -Tpe -x -Gn -v -LC:\CBuilderX\lib c0x32.obj windows\Debug_Build\File1.obj,"C:\Documents and Settings\StealthOp1217\cbproject\ConsoleApp1\windows\Debug_Build\ConsoleApp1.exe",,cw32.lib import32.lib,,
Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland

Error: Unresolved external '_main' referenced from C:\CBUILDERX\LIB\C0X32.OBJ

ILINK32 exited with error code: 2
Build cancelled due to errors

please, post your code in code tags, it makes it much easier for people to help you! :)

i don't know, but i cut and paste your code exactly and it compiled - and ran, just fine for me.

compiler: mingw
IDE: Dev-C++ (4.9.9.1)
Last edited on
If you use VC, the error may be caused by /SUBSYSTEM, one of linker's switches. It can be set as "CONSOLE" for CUI application and "WINDOWS" for GUI application, respectively. When linking, the linker will look for _main if /SUBSYSTEM:CONSOLE is set.
The solutions:
1. Click on the Link tab of the Project Settings dialog box and change the /SUBSYSTEM:CONSOLE switch to /SUBSYSTEM: WINDOWS.

2. Click on the Link tab of the Project Settings dialog box and delete the /SUBSYSTEM:WINDOWS switch entirely. Now, the linker will simply do the right thing based on which function you implement in your source code.
Topic archived. No new replies allowed.