Solved

Unicode to ASCII

Posted on 2000-02-18
6
319 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 48
mixString challenge 36 111
FizzBuzz challenge 9 76
My project did see openJDK that I installed. What could be the problem 7 122
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now