Jump to content
  • Advertisement
Sign in to follow this  
Reegan

Trouble with windows programming C++

This topic is 3835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Thanks for trying but neither of those worked they both returned the error "identifer not found".

any other suggestions? *hopeful*

Share this post


Link to post
Share on other sites
try changing this

int APIENTRY WinMain(HINSTANCE hInstance,

to this

int WINAPI WinMain(HINSTANCE hInstance,


That should fix the problem.

Share this post


Link to post
Share on other sites
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 ==========

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!