Home > Software engineering >  About the Unicode version VB API calls
About the Unicode version VB API calls

Time:09-18

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameW" (ByVal lpBuffer As String, nSize) As Long As Long


Private Sub Command2_Click ()
Dim STR As String * 255
GetComputerName STR, 255
StrConv STR, vbFromUnicode
Can display properly

End Sub

CodePudding user response:

The
refer to the original poster vhvihs0668 response:
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameW" (ByVal lpBuffer As String, nSize As Long) As Long


Private Sub Command2_Click ()
Dim STR As String * 255
GetComputerName STR, 255
StrConv STR, vbFromUnicode
Can display properly

End Sub

The building Lord, your problem is?

CodePudding user response:

If you Declare, to use W version of the API functions, so "String" cannot use type String, only preach "pointer",
Such use, for example, you can retrieve data "right" :
 Option Explicit 

Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameW" (_
ByVal lpBuffer As Long, _
ByRef nSize) As Long As Long

Private Sub Command1_Click ()
Dim strTemp As String
Dim w As Long

W=255 & amp; 'length of buffer
StrTemp=String $(w, vbNullChar)
Call GetComputerName (StrPtr (strTemp), w)
Me. The Caption=Left $(strTemp, w)
End Sub

CodePudding user response:

Who calls through the API function Declare statement, all of the String parameter in the call, returns, it should be "implied encoding conversion",

As a result, the code in your ZhuTie, original API functions in "character data buffer" into the Unicode string.
But after the "returns", VB6 and regard it as the ANSI format code "quietly" give you "convert Unicode",
So you must have "came back from the Unicode conversion" to display properly,

Results: the original "don't need to convert the string coding", but it happened in your code conversion for three times...

CodePudding user response:

reference Chen8013 reply: 3/f
anyone who calls through the API function Declare statement, all of the String parameter in the call, returns, it should be "implied encoding conversion",

As a result, the code in your ZhuTie, original API functions in "character data buffer" into the Unicode string.
But after the "returns", VB6 and regard it as the ANSI format code "quietly" give you "convert Unicode",
So you must have "came back from the Unicode conversion" to display properly,

Results: the original "don't need to convert the string coding", but it happened in your code conversion for three times...


Studied the
  •  Tags:  
  • API
  • Related