Problem with creating an window

closed account (ozUkoG1T)
hey c++ i have copied and pasted an code from MSDN,yet the code does not work.
how is it me or Microsoft i doubt it is them but any way :
1
2
3
4
5
6
#include<Windows.h>
int  APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR    lpCmdLine, int       nCmdShow)
{
MessageBox(NULL, L"MessageBox Text", L"MessageBox caption", MB_OK);
     return FALSE;
}

what is the error please...
p.s
If you know an easier way to make an simple window please post it thanks
Just wondering, did you put that code into a Win32 project? Or Win32 Console Application?
closed account (ozUkoG1T)
win32 project
Just get rid of the '_t' in behind WinMain, it worked fine for me once I did that
Or include tchar.h :)
closed account (ozUkoG1T)
hey all but when i did both i still got an error "WinMain" function cannot be overloaded

please help!
It shouldn't be saying it overloaded with that code, and including tchar.h like modoran said it still works fine.

Which compiler are you using? And post the source and error message too.
closed account (ozUkoG1T)
i am using visual studio 2010 ultimate the error code is :

source
1
2
3
4
5
6
#include<Windows.h>
int  APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR    lpCmdLine, int       nCmdShow)
{
MessageBox(NULL, L"MessageBox Text", L"MessageBox caption", MB_OK);
     return TRUE;
}
Error	1	error C2731: 'WinMain' : function cannot be overloaded	c:\users\Cyberwarfare\desktop\c programs & project\networking\networking\server.cpp	      3  	1	Networking
Alright, where it saids LPTSTR, I changed that to LPSTR and it worked fine for me.

If you used _tWinMain and include tchar.h it will work too.
closed account (ozUkoG1T)
still no progress not an single success run
1
2
3
4
5
6
7
#include<Windows.h>
#include<tchar.h>
int  APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int       nCmdShow)
{
MessageBox(NULL, L"MessageBox Text",L"MessageBox caption", MB_OK);
     return TRUE;
}

please write the correct code for me to actually run please
Error	1	error C2731: 'wWinMain' : function cannot be overloaded	c:\users\rohan vijjhalwar\desktop\c programs & project\networking\networking\server.cpp	4	1	Networking
Last edited on
1) The entry point is WinMain, not _tWinMain

2) WinMain takes LPSTR, not LPTSTR

3) No need to #include <tchar.h>

1
2
3
4
5
6
7
8
9
#include <Windows.h>

int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show)
{
   //...

   return 0;  // <- returning 0 indicates success, just like with the normal main().
    // return TRUE is the same as return 1, which indicates failure.
}
Last edited on
Yeah, looking at the code I said one of the other, you done both!

It can either be like

1
2
3
4
5
6
7
#include <Windows.h>

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR    lpCmdLine, int       nCmdShow)
{
	MessageBox(NULL, L"MessageBox Text", L"MessageBox caption", MB_OK);
        return 0;
}


Or

1
2
3
4
5
6
7
8
#include <Windows.h>
#include <tchar.h>

int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR    lpCmdLine, int       nCmdShow)
{
	MessageBox(NULL, L"MessageBox Text", L"MessageBox caption", MB_OK);
        return 0;
}


And what Disch said, returning 1 or TRUE is failure, as TRUE is just a macro for 1.
Last edited on
closed account (ozUkoG1T)
hey none of them seem to work what IDE or compiler you using please.
I'm using Microsoft Visual Studios 2010 Ultimate, the same as you. Just wondering did you crack your version? Because that might be why it not working but it should be fine.

Did Disch's code also not work?
If you are using MinGW try...
1
2
3
4
5
6
7
#include <Windows.h>
#include <tchar.h>
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR    lpCmdLine, int       nCmdShow)
{
	MessageBoxW(NULL, L"MessageBox Text", L"MessageBox caption", MB_OK);
	return 0;
}
Last edited on
closed account (ozUkoG1T)
Hey all again it does not work i did not crack it i have the Open gl lib and everything which came with it.again you're code or naraku or Disch code did not work at all.
closed account (ozUkoG1T)
anyone know but i copied some window code about an week ago and that one works but do not know why any of these dont work
Then I'm really not sure, OpenGL got nothing to do with the code so it won't be anything to do with that.

Just try making a new Win32 Project and make sure it empty then try the code again.

Or try that code below.

1
2
3
4
5
6
7
#include <Windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MessageBox(NULL, L"Text", L"Caption", MB_OK);
	return 0;
}
closed account (ozUkoG1T)
Yes finnaly it is working thanks Callum !!!!
I feel I must interject with a technical correction.

MessageBox(NULL, L"Text", L"Caption", MB_OK);

This is wrong. MessageBox takes TCHAR strings, you are giving it WCHAR strings.

1
2
3
MessageBoxA(NULL, "Text", "Caption", MB_OK);  // <- Correct.  ANSI ver of the function with char strings
MessageBoxW(NULL, L"Text", L"Caption", MB_OK);  // <- Correct.  Wide ver of the function with wide strings
MessageBox(NULL, TEXT("Text"), TEXT("Caption"), MB_OK); // <- Correct. TCHAR ver of the function with TCHAR strings 


Whether or not passing wide strings to a TCHAR version of the function will work depends on whether or not UNICODE is defined (depends on your compiler settings or whether you are manually #defining it).

Best practice: pick one and run with it. Don't mix and match.

I personally try to use the 'W' version of all WinAPI functions whenever practical.
Last edited on
Topic archived. No new replies allowed.