Problem with creating an window
Cyberwarfare (112)
Sep 22, 2012 at 6:51pm UTC
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
Callum5042 (125)
Sep 22, 2012 at 7:57pm UTC
Just wondering, did you put that code into a Win32 project? Or Win32 Console Application?
Callum5042 (125)
Sep 22, 2012 at 10:37pm UTC
Just get rid of the '_t' in behind WinMain, it worked fine for me once I did that
Cyberwarfare (112)
Sep 23, 2012 at 9:48am UTC
hey all but when i did both i still got an error "WinMain" function cannot be overloaded
please help!
Callum5042 (125)
Sep 23, 2012 at 11:22am UTC
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.
Cyberwarfare (112)
Sep 23, 2012 at 11:56am UTC
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
Callum5042 (125)
Sep 23, 2012 at 4:42pm UTC
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.
Cyberwarfare (112)
Sep 23, 2012 at 5:07pm UTC
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 Sep 23, 2012 at 5:08pm UTC
Disch (8349)
Sep 23, 2012 at 5:15pm UTC
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 Sep 23, 2012 at 5:16pm UTC
Callum5042 (125)
Sep 23, 2012 at 5:29pm UTC
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 Sep 23, 2012 at 5:30pm UTC
Cyberwarfare (112)
Sep 23, 2012 at 5:31pm UTC
hey none of them seem to work what IDE or compiler you using please.
Callum5042 (125)
Sep 23, 2012 at 5:50pm UTC
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?
naraku9333 (923)
Sep 23, 2012 at 5:59pm UTC
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 Sep 23, 2012 at 6:00pm UTC
Cyberwarfare (112)
Sep 23, 2012 at 6:08pm UTC
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.
Cyberwarfare (112)
Sep 23, 2012 at 6:12pm UTC
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
Callum5042 (125)
Sep 23, 2012 at 6:14pm UTC
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;
}
Cyberwarfare (112)
Sep 23, 2012 at 6:24pm UTC
Yes finnaly it is working thanks Callum !!!!
Disch (8349)
Sep 23, 2012 at 9:44pm UTC
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 Sep 23, 2012 at 9:45pm UTC
Topic archived. No new replies allowed.