by Michael S. Kaplan, published on 2006/10/08 17:23 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/10/08/806138.aspx
Greg Marmalard: You're talking about Visual Basic, sir.
Dean Vernon Wormer: Of course I'm talking about Visual Basic, you twerp! This applicatiion, it's gonna be different. This year we're gonna take the binary by its PDB and convert those strings into Unicode.
Greg Marmalard: What do you intend to do sir? VB strings are already in Unicode.
Dean Vernon Wormer: They are?
Greg Marmalard: Yes sir.
Dean Vernon Wormer: Well then as of this moment they will be converted to Double Secret Unicode!
Take a gander at the following code excerpt (it has a few problems in it!):
100 si.cb = Len(si)
110 wUser = StrConv(UserName + Chr$(0), vbUnicode)
120 wDomain = StrConv(DomainName + Chr$(0), vbUnicode)
130 wPassword = StrConv(Password + Chr$(0), vbUnicode)
140 wCommandLine = StrConv(CommandLine + Chr$(0), vbUnicode)
150 wCurrentDir = StrConv(CurrentDirectory + Chr$(0), vbUnicode)
160 If regDoes_Key_Exist(HKEY_LOCAL_MACHINE, "CLUSTER") Then
170 Print #nLogFile, " This is a cluster so LOGON_WITH_PROFILE wiil be used."
180 Print #nLogFile, "Parameters to CreateProcessWithinLogonW=" & _
wUser & "," & wDomain & "," & "wPassword", _
LOGON_WITH_PROFILE & "," & 0 & "," & wCommandLine & "," & _
CREATE_DEFAULT_ERROR_MODE & "," & 0 & "," & "," & _
190 Result = CreateProcessWithLogonW(wUser, wDomain, wPassword, _
LOGON_WITH_PROFILE, 0&, wCommandLine, _
CREATE_DEFAULT_ERROR_MODE, 0&, wCurrentDir, si, pi)
The first problem is not an international one, it is that si, well specifically the lpDesktop member, has to be set to something if the code is not meant to be run interactively. But that is not what this post is about.
The second problem is one that you may remember if you have seen It isn't Unicode, it's Double Secret Unicode! in the past.
The simple truth is that with the except of Windows Codepage 1256 (Arabic), every single code page can lose information outside of it if you try to roundtrip the information through Unicode. And code that converts Unicode text to Unicode again and then converts it back is guaranteed therefore to lose information in some cases. Which is really a bad idea (in addition to a slower one, given six extraneous string conversions?).
So please just say no to Double Secret Unicode! Don't let Dean Wormer have his way....
This post brought to you by ∂ (U+2202, a.k.a. PARTIAL DIFFERENTIAL)
# Igor on 9 Oct 2006 12:00 AM:
go to newer or older post, or back to index or month or day