• Welcome to Dark Bit Factory & Gravity.
 

Elementary error? Hello world gone wrong!

Started by Shockwave, March 08, 2007

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Shockwave

Huh?

I get this error;

1>.\Hullo.cpp(6) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'

Here is the source...


#include <IOSTREAM>
#include <WINDOWS.H>

int main()
{
MessageBox (0, "text" ,"caption", 0);
std::cout << "Hello World\n";
return 0;
}


Which looks okay to me..

It compiles and runs ok without ;
   MessageBox (0, "text" ,"caption", 0);

Shockwave ^ Codigos
Challenge Trophies Won:

benny!

This could be an unicode / ansi related problem. Try this instead  :

Quote
#include <IOSTREAM>
#include <WINDOWS.H>

int main()
{
   MessageBox (0, TEXT("text") ,TEXT("caption"), 0);
   std::cout << "Hello World\n";
   return 0;
}
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Shockwave

Because I have been so frustrated by this and so stressed out I am very grateful to you.
Basically you've done a lot to fix my problems so what can I say?

As an admin of the forum, Karma is easy for me to give, but what you need to know is that you have given me confidence that my C++ installation now works, so what I decided to do was remove some of my own Karma and give it to you and rbraz, all my Karma has been awarded in good faith by people and I think it will show you how greatful I am.

Thank you Benny. And Thanks to Rbraz for the api example.
Shockwave ^ Codigos
Challenge Trophies Won:

benny!

Wow shocky, that's very kind. Thanks a lot for that outstanding karma boost.

I am glad if I could helped you. C++ is very frustrating especially in the beginning.
So, good luck for your further steps with C++. I am of course willing to help where
I can...

K++ for such a nice gesture  ;)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Paul

Shockwave, your original code worked fine for me in dev c++
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Shockwave

Thanks Paul :)

You would not believe the hassles I had setting up Visual Studio.. People tell me it's worth it though!
Shockwave ^ Codigos
Challenge Trophies Won:

Paul

I installed the express version but i kinda like dev
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

ferris

I prefer dev, it produces executables like .5k larger but it has string libraries by default to avoid problems like this.
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Shockwave

After driving a delivery van for too many years and learning all the wrong languages, the whole commercial world seems to use M$ so as much as I hate it, I suppose I should learn this.
Shockwave ^ Codigos
Challenge Trophies Won:

benny!

Quote from: Shockwave on March 08, 2007
After driving a delivery van for too many years and learning all the wrong languages, the whole commercial world seems to use M$ so as much as I hate it, I suppose I should learn this.

Right. I guess, if you decide to learn C++ in the M$-World, I also would suggest to
go with the Visual Suite. In addition, remember that you can use the IDE for mulitple
purposes (C#, .NET and so on....)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Rbz

Quote from: benny! on March 08, 2007
This could be an unicode / ansi related problem. Try this instead  :

Quote
#include <IOSTREAM>
#include <WINDOWS.H>

int main()
{
   MessageBox (0, TEXT("text") ,TEXT("caption"), 0);
   std::cout << "Hello World\n";
   return 0;
}


Yup, definitely this is a problem with unicode X ansi, to fix this, go to "Project" Properties -> Configurations Properties -> General -> Character Set -> and select "Not Set"

Challenge Trophies Won:

Shockwave

Thanks Rbraz, question, do I need to do this for every project?
Shockwave ^ Codigos
Challenge Trophies Won:

Tetra

I had the exact same problem when I first tried to make a program in VS too ^^, hadnt read this post till now though, your not alone :D
Challenge Trophies Won:

Rbz

Quote from: Shockwave on March 09, 2007
Thanks Rbraz, question, do I need to do this for every project?

There's a way to modify this default option.

Find the file: default.js located in ..\Microsoft Visual Studio 8\VC\VCWizards\AppWiz\Generic\Application\scripts\1033

Open it with notepad (don't forget to make a backup copy of default.js), search for this line:

config.CharacterSet = charSetUNICODE;

and change it to:

config.CharacterSet = charSetNotSet;

Now your default option for character set will be always "not set" (Ansi)
Challenge Trophies Won:

Shockwave

Shockwave ^ Codigos
Challenge Trophies Won:

Jim

That one caught me out too, for a bit :).  Microsoft changed the default character size to 16bit unicode between VS2003 and VS2005.

Another way round it is to add
#undef UNICODE
as the very first line of your source, but it's better to change it in the options.

Jim
Challenge Trophies Won: