views:

184

answers:

3

I have a windows DLL that currently only supports ASCII and I need to update it to work with Unicode strings. This DLL currently uses char* strings in a number of places, along with making a number of ASCII Windows API calls (like GetWindowTextA, RegQueryValueExA, CreateFileA, etc).

I want to switch to using the unicode/ascii macros defined in VC++. So instead of char or CHAR I'd use TCHAR. For char* I'd use LPTSTR. And I think things like sprintf_s would be changed to _stprintf_s.

I've never really dealt with unicode before, so I'm wondering if there are any common pitfalls I should look out for while doing this. Should it just be as simple as replacing the types and method names with the proper macros be enough, or are there other complications to look out for?

+3  A: 

First read this article by Joel Spolsky: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Then run through these links on StackOverflow: What do I need to know about Unicode?

Generally, you are looking for any code that assumes one character = one byte (memory/buffer allocation, etc). But the links above will give you a pretty good rundown of the details.

Enjoy,

Robert C. Cartaino

Robert Cartaino
The raw memory stuff I'm pretty set on. I'm more worried about Win API issues I might run into, or corner cases that might not be immediately obvious.
Herms
+1  A: 

The biggest danger is likely to be buffer sizes. If your memory allocations are made in terms of sizeof(TCHAR) you'll probably be OK, but if there is code where the original programmer was assuming that characters were 1 byte each and they used integers in malloc statements, that's hard to do a global search for.

Clyde
Just grepped for malloc and it's only used in a couple places, and only once for a string buffer. new is used in most places (and I'd rather it be used everywhere. I don't like mixed allocation techniques). I think I'm covered here.
Herms
A: 

Píani Oshobia EX bewildered by the DLL format.

Prong