Sign in to follow this  

Problem with wide chars in VC++ 2005 Express

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay I got a new problem in Visual C++ 2005 Express. I created a win32 program and loaded my opengl template code. After templewulf and SiCrane told me how to link libs in VC++ 2005, I tried to build it and had another error. I had made a global character array called ProgramName, and I had been just inserting the name of my program in there everytime I used the template for a different program. (I know, everyone says to use strings but I'm hard headed =) ). Well, in VC++ when I tried to compile it, it gave me this error: 'CreateWindowExW' : cannot convert parameter 2 from 'char [9]' to 'LPCWSTR' Also it complained about the same thing for my message boxes. I looked around a little and finally realized that CreateWindowExW and MessageBoxW are for wide characters, not regular ones. And CreateWindowEx and MessageBox are typedefed to the FunctionNameWs if UNICODE is defined and FunctionNameA if it's not. I believe this is the source of my problems. So why and where is UNICODE defined? Because I don't want it to be. Also, as a "side question", I noticed that when I tried to use my input method editor to enter japanese characters in my old VC++ 6.0 Introductory Edition, it replaced them with questions marks. But VC++ 2005 Express doesn't. So I thought I could now use japanese characters in my programs, but when changed my ProgramName array to a WCHAR array and tried to compile it, after telling me I'd need to save my cpp file in unicode format, it gave me these errors:
------ Build started: Project: Degenetron, Configuration: Debug Win32 ------
Compiling...
Degenetron.cpp
c:\documents and settings\owner\desktop\icon folder\opengl programming stuff\degenetron\degenetron\degenetron.cpp(9) : warning C4566: character represented by universal-character-name '\u30C7' cannot be represented in the current code page (1252)
c:\documents and settings\owner\desktop\icon folder\opengl programming stuff\degenetron\degenetron\degenetron.cpp(9) : warning C4566: character represented by universal-character-name '\u30B8' cannot be represented in the current code page (1252)
c:\documents and settings\owner\desktop\icon folder\opengl programming stuff\degenetron\degenetron\degenetron.cpp(9) : warning C4566: character represented by universal-character-name '\u30A7' cannot be represented in the current code page (1252)
c:\documents and settings\owner\desktop\icon folder\opengl programming stuff\degenetron\degenetron\degenetron.cpp(9) : warning C4566: character represented by universal-character-name '\u30CD' cannot be represented in the current code page (1252)
c:\documents and settings\owner\desktop\icon folder\opengl programming stuff\degenetron\degenetron\degenetron.cpp(9) : warning C4566: character represented by universal-character-name '\u30C8' cannot be represented in the current code page (1252)
c:\documents and settings\owner\desktop\icon folder\opengl programming stuff\degenetron\degenetron\degenetron.cpp(9) : warning C4566: character represented by universal-character-name '\u30ED' cannot be represented in the current code page (1252)
c:\documents and settings\owner\desktop\icon folder\opengl programming stuff\degenetron\degenetron\degenetron.cpp(9) : warning C4566: character represented by universal-character-name '\u30F3' cannot be represented in the current code page (1252)
c:\documents and settings\owner\desktop\icon folder\opengl programming stuff\degenetron\degenetron\degenetron.cpp(9) : error C2440: 'initializing' : cannot convert from 'const char [8]' to 'WCHAR []'
        There is no context in which this conversion is possible
Build log was saved at "file://c:\Documents and Settings\Owner\Desktop\Icon Folder\OpenGL Programming Stuff\Degenetron\Degenetron\Debug\BuildLog.htm"
Degenetron - 1 error(s), 7 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What does it mean they can't be represented? They are represented. At least I can see them, and they're not replaced with question marks. At any rate, what I really want is to get the compiler back to the way it was before, with regular 8-bit characters. Help would be appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites
For the first part of your problem: go to your project settings, under general, go to the character set option and change it from Unicode to Multi-Byte. That should undefine UNICODE.

Share this post


Link to post
Share on other sites
For the other part, codepage 1252 is the 8 bit ANSI codepage, which obviously can not represent unicode characters (codepage 1200 for instance) that are not in it. To fix that problem, simply save the source code files to be saved as unicode files. Select the file, then go to File->Advanced Save Options and set the encoding to 1200 or someother unicode format.

Share this post


Link to post
Share on other sites
I tried File->Advanced Save Options and selected Unicode - Codepage 1200 from the encoding list. But it still gave me the same errors.

Then I try saving it in a few of the japanese ones (like "Japanese (Shift-Jis) - Codepage 932"), and it gives me this error:

error C2440: 'initializing' : cannot convert from 'const char [25]' to 'WCHAR []'

So then I change the WCHAR array to a char array and it compiles, but when I execute the program, it's not what I entered at all, just some screwed up junk.

I mean this isn't really all that important. I used to be/kind of still am interested in japanese and I learned the kana, but I don't really *know* japanese and will likely never make a program that needs to use japanese characters. But it's still kind of annoying that I can't get the program to work. So if you know any other reasons this isn't work, it would be appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites
that junk is the charset default , it's used when the the app can't find the charechtar you
specfied. make sure you have fonts that support the lang your writing in .i don't really know
how many letters there is in a japanese alphabet , but if there is more that (2^8)256 , you
should have unicode enabled.so you can have more than 8-bits for each letter.



Share this post


Link to post
Share on other sites
Quote:
Original post by K A Z E
error C2440: 'initializing' : cannot convert from 'const char [25]' to 'WCHAR []'


yeah, i think you are defining text incorrectly...

char str[] = "ascii";
wchar_t wstr[] = L"unicode"; // <<-- NOTE: capital L infront of "

normally you use the TEXT() macro for this, ie :

TEXT("text string")

which should sort that for you.

Share this post


Link to post
Share on other sites
Ah, okay. Yeah I had the charset on multi byte. And the L is why it was complaining when I was trying to define the WCHAR array.

Thank you both. =)

Share this post


Link to post
Share on other sites

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this