Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Shockwave on March 08, 2007

Title: Elementary error? Hello world gone wrong!
Post by: Shockwave on March 08, 2007
Huh?

I get this error;

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

Code: [Select]
#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);

Title: Re: Elementary error? Hello world gone wrong!
Post by: 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;
}
Title: Re: Elementary error? Hello world gone wrong!
Post by: Shockwave on March 08, 2007
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.
Title: Re: Elementary error? Hello world gone wrong!
Post by: benny! on March 08, 2007
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  ;)
Title: Re: Elementary error? Hello world gone wrong!
Post by: Paul on March 08, 2007
Shockwave, your original code worked fine for me in dev c++
Title: Re: Elementary error? Hello world gone wrong!
Post by: Shockwave on March 08, 2007
Thanks Paul :)

You would not believe the hassles I had setting up Visual Studio.. People tell me it's worth it though!
Title: Re: Elementary error? Hello world gone wrong!
Post by: Paul on March 08, 2007
I installed the express version but i kinda like dev
Title: Re: Elementary error? Hello world gone wrong!
Post by: ferris on March 08, 2007
I prefer dev, it produces executables like .5k larger but it has string libraries by default to avoid problems like this.
Title: Re: Elementary error? Hello world gone wrong!
Post by: 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.
Title: Re: Elementary error? Hello world gone wrong!
Post by: benny! 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....)
Title: Re: Elementary error? Hello world gone wrong!
Post by: Rbz 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"

 
Title: Re: Elementary error? Hello world gone wrong!
Post by: Shockwave on March 09, 2007
Thanks Rbraz, question, do I need to do this for every project?
Title: Re: Elementary error? Hello world gone wrong!
Post by: Tetra on March 09, 2007
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
Title: Re: Elementary error? Hello world gone wrong!
Post by: Rbz on March 10, 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)
Title: Re: Elementary error? Hello world gone wrong!
Post by: Shockwave on March 10, 2007
Thanks Rbraz :)
Title: Re: Elementary error? Hello world gone wrong!
Post by: Jim on March 11, 2007
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
Code: [Select]
#undef UNICODEas the very first line of your source, but it's better to change it in the options.

Jim