Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

Unicode to ASCII

Hi there..

I have an application that wants to use some old code once developed on unix, then ported to win32. I am developing my app on NT4.0.

The old code resides in a static library, and needs a char* as a parameter. My problem is that I am reading this parameter from the registry, and then passing it on to this old function. What I get back from the registry is a unicode string (wchar_t or CString if you like) and I need to convert this to a char* with characters of 8bits..

I know it's possible, but how??
0
lar_jens
Asked:
lar_jens
  • 3
  • 3
1 Solution
 
ScottyDawgCommented:
This sort of thing is also a problem when calling something like ExecuteSQL which expects and ASCII string and will fail if it gets something in UNICODE.

An API called

WideCharToMultiByte(...)

should help you out :)
0
 
lar_jensAuthor Commented:
No this is not exactly what I want.. I need something that makes me 100% sure that the characters I send to my old function is 8 bits wide, nothing more, nothing less..
0
 
ScottyDawgCommented:
By specifiying CP_ACP I assumed that's exactly what you get - why not?

CString   strUnicode = _T("A unicode string");
   char*     szAscii = new char[strUnicode.GetLength() + 1];

   WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, szAscii, strUnicode.GetLength() + 1, NULL, NULL);
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
lar_jensAuthor Commented:
OK.. Wait a second.. I will try it out. I just thought that the multibyte character sets was wider than 8-bit..
0
 
lar_jensAuthor Commented:
You were right. I'm sorry.. Here's your points.. You've earned them..
0
 
ScottyDawgCommented:
Glad to help, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now