Trouble with windows programming C++

Started by
18 comments, last by Crypter 16 years, 2 months ago
Hello, im trying to figure out where im going wrong im following this tutorial online about windows programming. im using visual C++ 2008 express edition and here is the code that i have been asked to type.
#include <windows.h>

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	
	MessageBox(NULL, "\tHello World!", "My first windows app", NULL);
	return 0;
}
Im assuming the code is supposed to go in an empty native console application but i could be wrong. It says something about the second paranthesis in MessageBox thing having an error. If someone could correct the error and direct me to a better place to learn about windows programming, i would be very greatful. Thanks ~Reegan PS: i hate windows programming.. looks so difficult an complicated compared to other types of programming.
Advertisement
Having just gone through a windows programming class myself I believe I know the problem you are getting. If you surround the strings with _T it should compile and run. I forget the specific reason for this, it has something to do with a unicode/ascii compatibility or something of that nature. See below for what I was talking about:

MessageBox(NULL, _T("\tHello World!"), _T("My first windows app"), NULL);

I believe this should fix your problem. If it doesn't let me know.
fortunately for you its just a simple sintax error where you pass text info to the messagebox method you wrote:

MessageBox(NULL, "\tHello World!", "My first windows app", NULL);

your passing text as char where it should be pass as LPCWSTR, so simple add a L before the coutes, it should look something like this

MessageBox(NULL, L"\tHello World!", L"My first windows app", NULL);

hope this helps you, please let me know if this works
Don't forget to visit my blog here.
Hey! Just let noobs be noobs, after all, we once were noobs right?
Under Project Properties, the "Character Set" option default is "UNICODE", you can change that to either "Not Set" or "MultiByte", then you can use your strings as normal.

I'm not saying one way is better than the other. I'm just saying it's possible
Quote:Original post by stringa
Under Project Properties, the "Character Set" option default is "UNICODE", you can change that to either "Not Set" or "MultiByte", then you can use your strings as normal.

I'm not saying one way is better than the other. I'm just saying it's possible


thanks for this, i didnt know this can be done

Don't forget to visit my blog here.
Hey! Just let noobs be noobs, after all, we once were noobs right?
Thanks for trying but neither of those worked they both returned the error "identifer not found".

any other suggestions? *hopeful*
try changing this

int APIENTRY WinMain(HINSTANCE hInstance,

to this

int WINAPI WinMain(HINSTANCE hInstance,


That should fix the problem.
i dont know whats wrong, it is like the f of a float(0.0f), it worked in my pc( Windows XP, Visual Studio 2008 Professional,C++), here is my complete code with character set set to Unicode:

#include <windows.h>

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{

MessageBox(NULL, L"\tHello World!", L"My first windows app", NULL);
return 0;
}

and my output:

------ Build started: Project: Help, Configuration: Debug Win32 ------
Compiling...
main.cpp
Linking...
Embedding manifest...
Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\GameDev Help\Help\Help\Debug\BuildLog.htm"
Help - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Don't forget to visit my blog here.
Hey! Just let noobs be noobs, after all, we once were noobs right?
Still no luck, ill post the origional code and the error message i got at first

Code:
#include <windows.h>int APIENTRY WinMain(HINSTANCE hInstance,                     HINSTANCE hPrevInstance,                     LPSTR     lpCmdLine,                     int       nCmdShow){ 		MessageBox(NULL, "\tHello World!", "My first windows app", NULL);	return 0;}


Error messgage:
error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
sorry about this question but are you sure are adding mayus L no l??? if yes when you add it what error you get??? ill try to help you
Don't forget to visit my blog here.
Hey! Just let noobs be noobs, after all, we once were noobs right?

This topic is closed to new replies.

Advertisement