Solved

Unicode to ASCII

Posted on 2000-02-18
6
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
Change owner from userA to server Local Administrators 7 73
sum13 challenge 24 146
MaxSpan challenge 9 137
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 …
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.
Suggested Courses

738 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