Thread: Problem compiling simple code examples

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    11

    Problem compiling simple code examples

    Okay I am new to Windows programming in C++, so I am looking at various tutorials on the internet in order to learn about it. My problem is that none of the code examples so far have been compilable in Visual Studio, but compile just fine in Bloodshed Dev C++. I prefer using VS due to its much much nicer UI.

    Anyway.. An example would be this error: "cannot convert parameter 2 from 'const char[28]' to 'LPCWSTR' ". This is the case in this line of code:
    Code:
    MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
    which is taken from this example http://www.winprog.org/tutorial/simple_window.html

    Obviously it always happens when I try to implicitly convert a const char type to a LPCWSTR type (whatever that is). Anyone have a solution to this problem?


    Thanks in advance

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Are you trying to compile in UNICODE? Cause that could cause some problems. Try putting TEXT("Text Here") around your strings.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    11
    Hey thanks man that actually worked

    I disabled the unicode, and switched to something called "multi-byte character set" and I am now able to compile. Thanks a lot for your help

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Your welcome!

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    FYI, the LPCWSTR type means:

    Long
    Pointer
    to a
    Constant
    Wide
    STRing


  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    11
    hehe okay :-) ehhh now you all probably laugh your asses off, but what is a wide string? hehe... Windows has lots of weird types, but I'm looking forward to delve deeper into the universe and learn what it's all about.

  7. #7
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    Wide String is a String of 16 bit characters, iow, Unicode.
    As compared to a regular string which is just a char array.

  8. #8
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Wide String is a String of 16 bit characters, iow, Unicode.
    As compared to a regular string which is just a char array.
    A regular char array can be Unicode.
    Specifically, I believe Window's wide strings are UTF-16. A char array is usually ASCII, but it could just as well be UTF-8. You just have to know what encoding your string uses, otherwise, it's just data.

    Google should help you locate some reference material / tutorials on Unicode in Windows.
    Last edited by Cactus_Hugger; 08-14-2007 at 07:42 AM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  9. #9

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple C programming
    By YAV in forum C Programming
    Replies: 2
    Last Post: 11-17-2008, 10:29 AM
  2. Problem in simple code.
    By richdb in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 02:45 AM
  3. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM