"CPP_Noob" <nospam@nowhere.org> wrote in message
news:PLZGl.16535$OO7.10934@text.news.virginmedia.com...
Hi,
I am a complete noob at VisC++ and copy/pasted some code the CD of a book
that Im using to learn VisC++. I am using MS VisC++ from VisStudio 2008
Express.
The ONLY source file that I have is named winmain.cpp (there are no other
files showing in the Solution Explorer, no resources or headers)
My "program" is failing with the error message:
error C2731: 'WinMain' : function cannot be overloaded c:\documents and
settings\genzzry\my documents\visual studio
2008\projects\cpp\directdraw\initialize\initialize\winmain.cpp 12
Initialize
Does anyone have any clue as to why this is?
I have checked MSDN and the entry point looks fine. There is also no
other code in my "program" so no other WinMain that Im aware of (unless
one is hiding inside windows.h)
If anyone could help or give me some pointers then this would be greatly
appreciated :os
Here is all my source for this "test" that doesnt compile for the above
stated error/reason:
// Include the Windows header file that's needed for all Windows
applications
#include <windows.h>
HINSTANCE hInst; // global handle to hold the application instance
HWND wndHandle; // global variable to hold the window handle
// forward declarations
bool initWindow( HINSTANCE hInstance );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
// This is winmain, the main entry point for Windows applications
int WINAPI WinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow )
{
// Initialize the window
if ( !initWindow( hInstance ) )
return false;
// main message loop:
MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message!=WM_QUIT )
{
// Check the message queue
while (GetMessage(&msg, wndHandle, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
return (int) msg.wParam;
}
I decided to do a bit more looking around and try alternative google
searches (previous ones had failed to return anything that helped).
I found that my entry point should be:
int WINAPI WinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
not:
int WINAPI WinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow )
Basically, I was using LPTSTR instead of LPSTR which apparently is due to
my book being obsolete already :os
LPTSTR maps to either LPSTR or LPWSTR depending on projects setting. There
obsolete. They just never tested it with a Unicode build or they would have
caught it.