HighTechTalks DotNet Forums  

Multi-byte characters?

Dotnet Internationalization microsoft.public.dotnet.internationalization


Discuss Multi-byte characters? in the Dotnet Internationalization forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Bob Altman
 
Posts: n/a

Default Multi-byte characters? - 06-23-2007 , 07:05 PM






If I create a new Win32 Console project (unmanaged C++, Visual Studio 2005),
and add the following to the main program:

// Add this above the main routine
#include <windows.h> // Add this at the top of the file

// Add this to the main routine
MessageBox(NULL, "A", "B", MB_OK);

The compiler (Visual Studio 2005) complains that it can't convert parameter
2 from 'const char [2]' to 'LPCWSTR'.

I don't understand why the compiler apparently thinks that I am using
multi-byte character semantics. The really bizarre part is that I have
another project that contains calls to MessageBox, and that project compiles
just fine. I've looked at the project properties in both projects, but I
can't see anything that would obviously cause one to compile correctly and
one to fail to compile.

This all began when I tried to write some code that formats a message and
sends it to the MessageBox function, like this:

ostringstream msg;
msg << "my message expression";
MessageBox(NULL, msg.str().c_str(), "Title", MB_OK);

In this case, the compiler complains that it can't convert parameter 2 from
'const char *' to 'LPCWSTR'. But, as I said, I have this identical code in
another project and it works just fine.

TIA - Bob



Reply With Quote
  #2  
Old   
Nathan Mates
 
Posts: n/a

Default Re: Multi-byte characters? - 06-23-2007 , 07:59 PM






In article <eWlY4retHHA.4612 (AT) TK2MSFTNGP04 (DOT) phx.gbl>,
Bob Altman <rda (AT) nospam (DOT) nospam> wrote:
Quote:
I don't understand why the compiler apparently thinks that I am using
multi-byte character semantics.
In DevStudio, this setting can be changed by right-clicking on your
project, selecting properties, then going to Configuration Properties
-> General -> Character Set. Turn off unicode, and go to multibyte
character set.

Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein


Reply With Quote
  #3  
Old   
ewpatton@gmail.com
 
Posts: n/a

Default Re: Multi-byte characters? - 06-24-2007 , 12:20 AM



On Jun 23, 7:05 pm, "Bob Altman" <r... (AT) nospam (DOT) nospam> wrote:
Quote:
If I create a new Win32 Console project (unmanaged C++, Visual Studio 2005),
and add the following to the main program:

// Add this above the main routine
#include <windows.h> // Add this at the top of the file

// Add this to the main routine
MessageBox(NULL, "A", "B", MB_OK);

The compiler (Visual Studio 2005) complains that it can't convert parameter
2 from 'const char [2]' to 'LPCWSTR'.

I don't understand why the compiler apparently thinks that I am using
multi-byte character semantics. The really bizarre part is that I have
another project that contains calls to MessageBox, and that project compiles
just fine. I've looked at the project properties in both projects, but I
can't see anything that would obviously cause one to compile correctly and
one to fail to compile.

This all began when I tried to write some code that formats a message and
sends it to the MessageBox function, like this:

ostringstream msg;
msg << "my message expression";
MessageBox(NULL, msg.str().c_str(), "Title", MB_OK);

In this case, the compiler complains that it can't convert parameter 2 from
'const char *' to 'LPCWSTR'. But, as I said, I have this identical code in
another project and it works just fine.

TIA - Bob
You can also put L in front of the string to tell the compiler it
should be expressed as a Unicode string rather than an ASCII string.



Reply With Quote
  #4  
Old   
SvenC
 
Posts: n/a

Default Re: Multi-byte characters? - 06-24-2007 , 05:23 AM



Hi,

Quote:
If I create a new Win32 Console project (unmanaged C++, Visual Studio
2005), and add the following to the main program:

// Add this above the main routine
#include <windows.h> // Add this at the top of the file

// Add this to the main routine
MessageBox(NULL, "A", "B", MB_OK);

The compiler (Visual Studio 2005) complains that it can't convert
parameter 2 from 'const char [2]' to 'LPCWSTR'.
Enclose all strings in _T() that ensures that the correct character type
(char or wchar_t) is used.

Quote:
I don't understand why the compiler apparently thinks that I am using
multi-byte character semantics. The really bizarre part is that I
have another project that contains calls to MessageBox, and that
project compiles just fine. I've looked at the project properties in
both projects, but I can't see anything that would obviously cause
one to compile correctly and one to fail to compile.
Project properties -> Configuration Properties -> General : Character Set

Quote:
This all began when I tried to write some code that formats a message
and sends it to the MessageBox function, like this:

ostringstream msg;
msg << "my message expression";
MessageBox(NULL, msg.str().c_str(), "Title", MB_OK);

In this case, the compiler complains that it can't convert parameter
2 from 'const char *' to 'LPCWSTR'. But, as I said, I have this
identical code in another project and it works just fine.
Define t-versions of those STL types based on TCHAR

#include <tchar.h>
#include <string>
#include <sstream>

typedef std::basic_ostringstream<TCHAR> tstringstream;
typedef std::basic_string<TCHAR> tstring;

tstringstream msg;
msg << _T("my message expression");
MessageBox(NULL, msg.c_str(), _T("Title"), MB_OK);

The above compiles with both Unicode and Multi byte settings.

--
SvenC



Reply With Quote
  #5  
Old   
Bob Altman
 
Posts: n/a

Default Re: Multi-byte characters? - 06-24-2007 , 12:27 PM



Mega cool. Thanks!!!

- Bob

"SvenC" <SvenC (AT) community (DOT) nospam> wrote

Quote:
Hi,

If I create a new Win32 Console project (unmanaged C++, Visual Studio
2005), and add the following to the main program:

// Add this above the main routine
#include <windows.h> // Add this at the top of the file

// Add this to the main routine
MessageBox(NULL, "A", "B", MB_OK);

The compiler (Visual Studio 2005) complains that it can't convert
parameter 2 from 'const char [2]' to 'LPCWSTR'.

Enclose all strings in _T() that ensures that the correct character type
(char or wchar_t) is used.

I don't understand why the compiler apparently thinks that I am using
multi-byte character semantics. The really bizarre part is that I
have another project that contains calls to MessageBox, and that
project compiles just fine. I've looked at the project properties in
both projects, but I can't see anything that would obviously cause
one to compile correctly and one to fail to compile.

Project properties -> Configuration Properties -> General : Character Set

This all began when I tried to write some code that formats a message
and sends it to the MessageBox function, like this:

ostringstream msg;
msg << "my message expression";
MessageBox(NULL, msg.str().c_str(), "Title", MB_OK);

In this case, the compiler complains that it can't convert parameter
2 from 'const char *' to 'LPCWSTR'. But, as I said, I have this
identical code in another project and it works just fine.

Define t-versions of those STL types based on TCHAR

#include <tchar.h
#include <string
#include <sstream

typedef std::basic_ostringstream<TCHAR> tstringstream;
typedef std::basic_string<TCHAR> tstring;

tstringstream msg;
msg << _T("my message expression");
MessageBox(NULL, msg.c_str(), _T("Title"), MB_OK);

The above compiles with both Unicode and Multi byte settings.

--
SvenC



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.