0

In my legacy VB6 application I'm receiving a zip file as a byte array from a webservice. This byte array is converted to a string using the StrConv function and stored on the file system.

Dim arr() As Byte
Dim sUnicode as String

nFile = FreeFile
arr = objHTTP.responseBody

sUnicode = StrConv(arr, vbUnicode)

Open sFile For Output As #nFile
Print #nFile, sUnicode
Close #nFile

So far so good, this has worked correctly for over a decade. Now the application is used in Japan as well and the code above leads to a corrupt zip file.

I already found out that the issue is related to the Japanese system locale on the target system.

I tried passing the locale id 1033 to the StrConv function

StrConv(arr, vbUnicode, 1033)

Next I tried implementing the solution as descibed by this link

Encoding of Text Files in VB 6.0

Also I tried changing the system locale using the 'SetLocaleInfo' api-call.

None of the attempts have lead to a valid zip file on a OS with the system locale set to Japanese.

Does anybody know how to get a working solution?

Thanks in advance,

Jos

Community
  • 1
  • 1

1 Answers1

1

You should avoid the string conversion entirely. Try something like this:

Dim arr() As Byte

nFile = FreeFile
arr = objHTTP.responseBody

Open sFile For Binary As #nFile
Put #nFile, , arr
Close #nFile

This writes the contents of your array directly to the file.

tcarvin
  • 10,715
  • 3
  • 31
  • 52
  • +1 Some byte sequences will not be valid strings in the Japanese encoding. You must avoid the use of strings entirely. – MarkJ Jun 03 '14 at 12:18