If it's the WideCharToMultiByte route does anyone have an VB example to
hand?
Thanks in advance,
Gavin.
> Can you use the VB StrConv function to convert unicode strings into
utf-8?
No. You only have an LCID parameter and no LCID has a default system
code page that is UTF-8.
> or do you have to use the WideCharToMultiByte API?
For an arbitrary string, yes. For a file, you can use the ADO Stream
object.
> If it's the WideCharToMultiByte route does anyone have an VB example
to
> hand?
There are code samples up at http://trigeminal.com/ for this.
--
MichKa [MS]
This posting is provided "AS IS" with
no warranties, and confers no rights.
Thanks for the link to your resource.
This sorted my problem.
I'd rejigged the your routines around to use byte arrays for the multi-byte
API parameters. With the AtoW() routine, the returned buffer is twice the
size as it should be because the function String( cwch + 1, vbNullchar)
allocated twice the amount of space it needed. The extra vbNull characters
caused me problems.
Again many thanks not just for responding to my postings, I've also found
your responses to other posts invaluable in my current assignment.
Regards,
Gavin Jones.
Should this be of internest to anyone else - here's the modified calls:
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage
As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal
cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As
Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage
As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal
cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As
Long, ByVal lpDefaultChar As Long, lpUsedDefaultChar As Long) As Long
Public Function UnicodeToMultiByte(st As String, cpg As Long) As Variant
Dim stBuffer As String
Dim cwch As Long
Dim pwz As Long
Dim pwzBuffer As Long
Dim b() As Byte
16200 pwz = StrPtr(st)
16210 cwch = WideCharToMultiByte(cpg, 0, pwz, -1, 0&, 0&, ByVal
0&, ByVal 0&)
16220 ReDim b(cwch - 1)
16230 pwzBuffer = VarPtr(b(0))
16240 cwch = WideCharToMultiByte(cpg, 0, pwz, -1, pwzBuffer, cwch,
ByVal 0&, ByVal 0&)
16250 ReDim Preserve b(cwch - 2) ' Strip off trailing chr(0)
16260 UnicodeToMultiByte = StrConv(b, vbUnicode)
End Function
Public Function MultiByteToUnicode(st As String, cpg As Long) As Variant
Dim stBuffer As String
Dim cwch As Long
Dim pwz As Long
Dim pwzBuffer As Long
Dim pwzBufferSize As Long
Dim b() As Byte
16360 b = StrConv(st, vbFromUnicode)
16370 pwz = VarPtr(b(0))
16390 cwch = MultiByteToWideChar(cpg, 0, pwz, -1, ByVal 0&, ByVal
0&)
16410 pwzBufferSize = cwch
16420 stBuffer = String(pwzBufferSize, " ")
16430 pwzBuffer = StrPtr(stBuffer)
16450 cwch = MultiByteToWideChar(cpg, 0, pwz, -1, pwzBuffer,
pwzBufferSize)
16470 MultiByteToUnicode = Left(stBuffer, cwch - 1)
End Function
"Michael (michka) Kaplan [MS]" <mic...@online.microsoft.com> wrote in
message news:#o#nAlU2C...@TK2MSFTNGP11.phx.gbl...
--
MichKa [MS]
This posting is provided "AS IS" with
no warranties, and confers no rights.
"Gavin G. Jones" <ga...@nospamgjit.com> wrote in message
news:OcLdLCl3...@TK2MSFTNGP11.phx.gbl...