Solved

Unicode to ASCII

Posted on 2000-02-18
6
317 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

18 Experts available now in Live!

Get 1:1 Help Now