Error using Windows classes ;o)

This is a discussion on Error using Windows classes ;o) within the C++ Programming forums, part of the General Programming Boards category; Hi, I've been trying to get a demo program for DirectX to run and I'm getting the following error log ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    87

    Cool Error using Windows classes ;o)

    Hi,

    I've been trying to get a demo program for DirectX to run and I'm getting the following error log when compiling:

    - cannot convert `const wchar_t[12]' to `const CHAR*' in assignment
    - cannot convert `const wchar_t*' to `const CHAR*' for argument `2' to `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'
    The code defines a structure of type WNDCLASSEX with a variable name called 'wc'. When it hits the following line:

    wc.lpszClassName = L"WindowClass";
    It gets mad. I checked out online what the structure WNDCLASSEX has as its defined data members and it seems the variable lpszClassName requires a pointer to a classname which is terminated with a null character - which as I understand can be represented with '/0'. I don't think the null character is an issue though as if you look it is complaining that an array called wchar_t[12] cannot convert to what looks like a pointer to a constant variable of type char - but written in capitals for some reason. Given that there are 11 letters in the name "Windowclass" then it follows that the code must have implemented a null character automatically as the array size is 12 not 11.

    I also thought an array variable was basically just read as a pointer by code too. So it seems to me that the data member of the structure WNDCLASSEX is being passed a pointer to a null terminated string, yet the program still complains.

    Can anyone shed any light on this, is this an issue relating to a windows version which is out of date or something? Cheers!

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    Change your project to use the Unicode character set. The tutorial apparently expects that, and your project is not setup for that.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    Btw, the null terminating char is '\0', not '/0'. They are not the same.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    87
    That is good info there chaps thanks alot. I changed the value from L"WindowClass" to just "WindowClass" and it ran fine. That Unicode concept is an eye opener it makes much sense now thanks. Guess I must have without even knowing it, created a file aimed specifically at running on Windows eh.

    Cheers

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Btw, all windows APIs use unicode strings internally (at least on NT-based versions, don't know about 9x/Me). For example, CreateWindowExA is just a wrapper that converts the arguments to unicode and calls CreateWindowExW

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    Unicode is not limited to Windows.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  2. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  3. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 05:57 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21