I'm trying to migrate a web application from a windows 2008 vps to a dedicated windows 2008 vps ( both 32bit edition ). The problem i noticed ( and i've fighting with it for more than 24 hours as of now ) is that most of the text comes in a garbled form ( and this ruins all of the application ). the app works like this: (html+js) -> php -> vb6 dll -> reply.
Initially i thought it must be an issue with encoding and iis but i think this is not the case. I narrowed down the problem to this:
when functions of the .dll are called, the string parameters of the functions are first parsed and translated to a vb6 proper format:
Public Function getCorrectStringNoTrans(ByVal strWord As String) As String If strWord <> "" Then If isUTF8 = False Then strWord = Trim$(strWord) Else Open "c:\log.txt" For Output As #1 Dim lol As Integer For lol = 1 To Len(strWord) Print #1, "bef:" & lol & ":" & Mid$(strWord, lol, 1) & ":" & AscW(Mid$(strWord, lol, 1)) & ":" & Asc(Mid$(strWord, lol, 1)) Next lol strWord = StrConv(strWord, vbFromUnicode) For lol = 1 To Len(strWord) Print #1, "aft:" & lol & ":" & Mid$(strWord, lol, 1) & ":" & AscW(Mid$(strWord, lol, 1)) & ":" & Asc(Mid$(strWord, lol, 1)) Next lol inData = strWord Dim c As New crc Dim lll As Long lll = UBound(inData) Print #1, c.CRC32(inData, lll) Close #1 strWord = Trim$(ConvertUtf8BytesToString(inData)) '''strWord = Replace$(Trim$(ConvertUtf8BytesToString(inData)), "\'", "'") End If End If getCorrectStringNoTrans = strWord End Function
So in live machine 1 ( the current one, which works properly ) the output for a specific string is ( the last number is a crc check ) :
bef:1:Ξ:926:206 bef:2:Ί:906:186 bef:3:Ξ:926:206 bef:4:±:177:177 bef:5:Ξ:926:206 bef:6:»:187:187 bef:7:Ο:927:207 bef:8::140:140 bef:9:Ο:927:207 bef:10:‚:8218:130 aft:1:?:-17714:63 aft:2:?:-20018:63 aft:3:?:-17458:63 aft:4:?:-29489:63 aft:5:?:-32049:63 1958248078
but in the new machine the output is:
bef:1:Ξ:926:206 bef:2:Ί:906:186 bef:3:Ξ:926:206 bef:4:±:177:177 bef:5:Ξ:926:206 bef:6:»:187:187 bef:7:Ο:927:207 bef:8::140:140 bef:9:Ο:927:207 bef:10:‚:8218:130 aft:1:?:16191:63 aft:2:?:-20161:63 aft:3:?:-17601:63 aft:4:?:16191:63 aft:5:?:-32193:63 523875602
so ascw() shows that the string gets messed up after strconv() in the new machine i'm trying to migrate to.
i have triple-checked the settings in control panel -> regional and language options and all settings are the same in BOTH machines:
formats tab: current format: greek
location tab: current location: greece
administrative tab: language for non-unicode programs: greek
Then i thought that maybe it's an issue with SP2, because the correctly working machine was sp2, and this one i'm experimenting was sp1, so i updated but alas, no results.
I don't understand why strconv() doesn't work as it should. Maybe I'm missing something in the settings or installation. Any ideas would be highly appreciated.
p.s. it also works correctly in a windows xp development machine with iis5.
You seem to be misunderstanding the encoding.If you're passed a string via COM, then it will already be unencoded and "raw" unicode (UCS-2) string. If you're being passed in UTF-8 you CAN NOT store it in a string until it's been decoded otherwise it will be corrupted. You must read non ANSI data as a byte array and decode as appropriate.
VB6 also has no native support for UTF-8.
vbFromUnicode are converting between byte arrays containing ANSI/MBCS data to VB strings in UCS-2.
In summary, assuming you are correctly being passed strings via COM, then the entire function can be replaced with