Author Topic: Elementary error? Hello world gone wrong!  (Read 8376 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
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);

Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Elementary error? Hello world gone wrong!
« Reply #1 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;
}
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Elementary error? Hello world gone wrong!
« Reply #2 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.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Elementary error? Hello world gone wrong!
« Reply #3 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  ;)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Elementary error? Hello world gone wrong!
« Reply #4 on: March 08, 2007 »
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:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Elementary error? Hello world gone wrong!
« Reply #5 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!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Elementary error? Hello world gone wrong!
« Reply #6 on: March 08, 2007 »
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:

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
Re: Elementary error? Hello world gone wrong!
« Reply #7 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.
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Elementary error? Hello world gone wrong!
« Reply #8 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.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Elementary error? Hello world gone wrong!
« Reply #9 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:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Elementary error? Hello world gone wrong!
« Reply #10 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:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Elementary error? Hello world gone wrong!
« Reply #11 on: March 09, 2007 »
Thanks Rbraz, question, do I need to do this for every project?
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Elementary error? Hello world gone wrong!
« Reply #12 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
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Elementary error? Hello world gone wrong!
« Reply #13 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)
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Elementary error? Hello world gone wrong!
« Reply #14 on: March 10, 2007 »
Thanks Rbraz :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Elementary error? Hello world gone wrong!
« Reply #15 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
Challenge Trophies Won: