Converting a project to Unicode: Part 2 ('Sorry, you're not my type.' 'Um, maybe I could change that?')

by Michael S. Kaplan, published on 2006/12/29 06:01 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/12/29/1377788.aspx


Previous posts in this series (including today's!):

The alternate title of this post is not something I would ever recommend using in a conversation about a relationship! 

Ok, first we'll start with the source code, you can either get it from the Platform SDK as I pointed out in Part 1, in the Samples\SysMgmt\Msi\setup.exe\ folder, or you can just download it from right here. So far nothing has happened to it -- this is our Tabula Rasa.

So now let's start dirtying it. :-)

I am going to stick it in its own folder (E:\SETUP.EXE\), navigate there from within Visual Studio 2005 Command Prompt and use either NMAKE to do a build (I have tested with the Platform SDK command prompt and others as well, the steps should work either way).

For starters, I'll make sure it can build:

Ok, good start. We probably won't be seeing success much until we are done so let's not get too used to it!

The first thing that has to happen is a search for uses of Unicode that are happening now -- obvious ones like types such as WCHAR, LPWSTR, and LPCWSTR. Clearly if there is anything that supports Unicode now we want to know where it is so that we can look at it more closely later when we decide what to do with it. Here are the results:

Find all "WCHAR", Whole word, Subfolders, Find Results 1, "All Open Documents"
E:\setup.exe\vertrust.cpp(193): WCHAR *szwSetup = 0;
E:\setup.exe\vertrust.cpp(194): WCHAR *szwPackage = 0;
E:\setup.exe\vertrust.cpp(226): szwSetup = new WCHAR[cchWide];
E:\setup.exe\vertrust.cpp(256): szwPackage = new WCHAR[cchWide];
E:\setup.exe\utils.cpp(232): WCHAR *pch = 0;
E:\setup.exe\utils.cpp(238): if ((pch = (WCHAR*)LockResource(hGlobal)) != 0)
Matching lines: 6 Matching files: 6 Total files searched: 10

Find all "LPCWSTR", Whole word, Subfolders, Find Results 1, "All Open Documents"
E:\setup.exe\vertrust.cpp(62):itvEnum IsFileTrusted(LPCWSTR lpwFile, HWND hwndParent, DWORD dwUIChoice, bool *pfIsSigned, PCCERT_CONTEXT *ppcSigner)
E:\setup.exe\setupui.h(87): HRESULT __stdcall OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText);
E:\setup.exe\setupui.h(88): HRESULT __stdcall OnStopBinding(HRESULT, LPCWSTR ) {return S_OK;}
E:\setup.exe\setupui.cpp(372):HRESULT CDownloadBindStatusCallback::OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR /*szStatusText*/)
E:\setup.exe\setup.h(85):itvEnum IsFileTrusted(LPCWSTR szwFile, HWND hwndParent, DWORD dwUIChoice, bool *pfIsSigned, PCCERT_CONTEXT *ppcSigner);
Matching lines: 5 Matching files: 6 Total files searched: 10

Find all "LPWSTR", Whole word, Subfolders, Find Results 1, "All Open Documents"
Matching lines: 0 Matching files: 0 Total files searched: 10

Find all "MultiByteToWideChar", Whole word, Subfolders, Find Results 1, "All Open Documents"
E:\setup.exe\vertrust.cpp(225): cchWide = MultiByteToWideChar(CP_ACP, 0, szSetupExe, -1, 0, 0);
E:\setup.exe\vertrust.cpp(233): if (0 == MultiByteToWideChar(CP_ACP, 0, szSetupExe, -1, szwSetup, cchWide))
E:\setup.exe\vertrust.cpp(255): cchWide = MultiByteToWideChar(CP_ACP, 0, szPackage, -1, 0, 0);
E:\setup.exe\vertrust.cpp(263): if (0 == MultiByteToWideChar(CP_ACP, 0, szPackage, -1, szwPackage, cchWide))
Matching lines: 4 Matching files: 6 Total files searched: 10

We'll set these lists aside for later, now that we know what they are.

Now of course this sets us up to the first set of changes -- using the handy dandy Replace in Files dialog:

Note the important settings here -- all open documents, match whole words, and using the Find Next button to review followed by the Replace button if we like the change.

LPSTR -> LPTSTR (less than 25 occurrences, no surprises other than perhaps a few that are on our "review later" list)

LPCSTR -> LPCTSTR (less than 100 occurrences, no surprises)

char --> TCHAR (over 100 occurrences, no big surprises in any of them)

Well, there are actually a few issues here that I will be talking about in later posts, but we're starting with the simple approach. :-)

And of course with these changes, note that we are not doing Unicode builds yet, so that so far the build will keep working.

Some things to look forward to here that I'll be talking about in upcoming posts:

Believe it or not, what was done today is likely the second most widespread change we'll have to do for this project!

Wasn't that easy? :-)

Stay tuned for the next step....

 

This post brought to you by  (U+0d17, a.k.a. MALAYALAM LETTER GA)


Mihai on 29 Dec 2006 7:07 PM:

The screen-shot shows a replacement of char with WCHAR (instead of TCHAR).

The text in the article is ok, but the image might puzzle some readers.

Michael S. Kaplan on 29 Dec 2006 7:58 PM:

Oops! Good catch there. :-)

Fixed now....

Michael S. Kaplan on 29 Dec 2006 11:28 PM:

(plus its always good to know people are reading?)

:-)

Mihai on 29 Dec 2006 11:43 PM:

<<plus its always good to know people are reading?>>

You can count on me reading. And if I don't say anything, it means you did not mess-up anything :-D

But this series I find very interesting. I did some Unicode migrations myself, but never had the opportunity to compare with what others do. Not much shared experience in this area (ok, there are some pages on MS Globaldev with generalities, but does not feel "real life").

I have already downloaded the original project and migrated it.

Now I am waiting and I am curious to compare it with your final result :-)

Michael S. Kaplan on 29 Dec 2006 11:54 PM:

I swear this is something I have had in the back of my brain since the question first popped up in the suggestion box -- there just never seemed to be the right project in front of me....

When this one popped up in my face as a bug report, I decided it had to be a sign from somewhere (Bob only knows where!) and I knew I just had to go with it. :-)


Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2007/12/24 VS just got served!, aka The ??? Shift, aka 'Converting a project to Unicode???' No, it's 'Converting a project??? ToUnicode!!!'

2007/01/05 Converting a project to Unicode: Part 9 (The project's postpartum postmortem)

2007/01/04 Converting a project to Unicode: Part 8 (Fitting MSLU into the mix)

2007/01/03 Converting a Project to Unicode: Part 7 (What does it mean to fit things to a 'T', anyway?)

2007/01/02 Converting a Project to Unicode: Part 6 (Upon the road not traveled)

2007/01/01 Converting a Project to Unicode: Part 5 (Are we there yet? Well, not *just* yet)

2006/12/31 Converting a Project to Unicode: Part 4 (It's /Delightful, it's /Delicious, it's /DUnicode!)

2006/12/30 Converting a project to Unicode: Part 3 (Can I quote you on that?)

go to newer or older post, or back to index or month or day