Solved

Unicode to ASCII

Posted on 2000-02-18
6
320 Views
Last Modified: 2013-11-20
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
Comment
Question by:lar_jens
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2534354
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
 
LVL 1

Author Comment

by:lar_jens
ID: 2534462
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
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 100 total points
ID: 2534481
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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 1

Author Comment

by:lar_jens
ID: 2534489
OK.. Wait a second.. I will try it out. I just thought that the multibyte character sets was wider than 8-bit..
0
 
LVL 1

Author Comment

by:lar_jens
ID: 2534647
You were right. I'm sorry.. Here's your points.. You've earned them..
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2534751
Glad to help, thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question