-
Nov 26th, 2014, 10:49 AM
#1
Thread Starter
New Member
GetPrivateProfileStringW - having trouble retrieving Chinese chars to display
I need to be able to read in Chinese characters and display them on a form. I found a previous post that showed how to retrieve them from the INI file and I have used that code but have not had success in displaying the value. Not sure if it is an API problem or a display problem.
The code is as follows:
Public Declare Function GetPrivateProfileStringW Lib "kernel32" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
lpReturnedString As Any, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Dim buf() As Byte
ReDim buf(254)
Dim theSection As String
theSection = "TEXTNCAPTIONS"
Dim theSize As Long
theSize = 255
Dim theCaption As String
theCaption = "USER ID:"
ReturnVal = GetPrivateProfileStringW(StrConv(theSection, vbUnicode), _
StrConv(theCaption, vbUnicode), _
StrConv(" ", vbUnicode), _
buf(0), _
theSize, _
StrConv(INIFileName, vbUnicode))
If ReturnVal <> 0 Then
NewString = StrConv(StrConv(Left(buf, ReturnVal), vbFromUnicode, 2052), vbUnicode)
If NewString <> "***" Then
frmObj.Font.name = ChrW(&H5B8B) + ChrW(&H4F53)
frmObj.Charset = 134
frmObj.Caption = NewString
End If
End If
Originally, I just had NewString = Left(buf, ReturnVal) but that was making NewString = ???, so I found the StrConv way of doing it above and it no longer puts ??? in NewString.
Instead, NewString = "Óû§Éí·Ý£º"
But, it is supposed to = 用户身份:
Any thoughts on how to solve this would be greatly appreciated.
-
Nov 26th, 2014, 12:56 PM
#2
Re: GetPrivateProfileStringW - having trouble retrieving Chinese chars to display
Lots of StrConv going on and may be adding to the problem. Let's remove all but the last one and see if results change any. Also, I believe you have to enable Far Eastern fonts in your system's regional settings
Here's the modified code. I'm not sure about seting the font name the way you did.
Looks like VB6 vs .Net, correct? If so, and if the operating system is theme enabled, to display a unicode caption on a form, you would use SendMesssage wm_settext to the default window procedure. Here's a sample link, read thru the posts. If it works for you, remove that final StrConv() line & font mods below
Code:
Public Declare Function GetPrivateProfileStringW Lib "kernel32" _
(ByVal lpApplicationName As Long, _
ByVal lpKeyName As Long, _
ByVal lpDefault As Long, _
ByVal lpReturnedString As Long, _
ByVal nSize As Long, _
ByVal lpFileName As Long) As Long
Dim buf As String
buf = String$(254, vbNullChar)
Dim theSection As String
theSection = "TEXTNCAPTIONS"
Dim theSize As Long
theSize = 255
Dim theCaption As String
theCaption = "USER ID:"
ReturnVal = GetPrivateProfileStringW(StrPtr(theSection), _
StrPtr(theCaption), _
StrPtr(" "), _
StrPtr(buf), _
theSize, _
StrPtr(INIFileName))
If ReturnVal <> 0 Then
NewString = StrConv(Left(buf, ReturnVal), vbFromUnicode, 2052)
If NewString <> "***" Then
frmObj.Font.Name = ChrW(&H5B8B) + ChrW(&H4F53)
frmObj.Charset = 134
frmObj.Caption = NewString
End If
End If
With VB6, you can pass a unicode string without using StrConv(). We change the API parameters to be Longs and then use StrPtr() on the passed string
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|