Coffeehouse Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

C++ troubles

Back to Forum: Coffeehouse
  • User profile image

    Im using the function

    to create a window in a win32 C++ app. The second and third arguments of this function allow a name and caption to be applied to the window.

    I try passing these in

    "like so","in quotes"

    and then it says they must be in the form of an LPCWSTR type.

    I try casting my strings to this type


    The projects compiles but at runtime the strings are garbled and the title of my windo shows


    Im pretty new to c++ and could use some help. Thanks in advance


  • User profile image
    Sven Groot

    This means you are compiling with UNICODE defined (I believe this is the default in VS2005, you can change it in the project properties, on the General page, the "Character set" option).

    Because you are using the unicode version of CreateWindowEx, you need to pass it a unicode string. If you type "Foo", it's an Ansi string. To make a Unicode string, you need to use L"Foo".

    Note however, that Windows 9x/Me don't support the Unicode version unless you use the Microsoft Layer for Unicode.

    If you want your application to compile regardless of whether unicode is defined or not, you can't just put L in front of your strings, because then it won't work if unicode isn't defined. Instead you can use a macro called TEXT, like so: TEXT("foo"). This will resolve to a unicode string if UNICODE is defined, and a multi-byte string otherwise.

  • User profile image

    tomtech999 wrote:
    and then it says they must be in the form of an LPCWSTR type.


    Wide characters .. like this      L"MyString"

    Edit: Gah beaten to it, one day I'll beat Sven to a C++ post ... try this though for clarification.

  • User profile image

    Thanks a lot guys

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.