CopyMemory ByVal StrPtr(LPWSTRtoBSTR), ByVal lpwsz, cChars * 2
End Function
从LPSTR到BSTR
将上面的小函数做一个小小的修改,我们就可以得到一个将LPSTR转换为BSTR的函数。(注意Trim函数的功能是去除前导空白和尾随空白)
Function LPSTRtoBSTR(ByVal lpsz As Long) As String
'''' Input: a valid LPSTR pointer lpsz
'''' Output: a sBSTR with the same character array
Dim cChars As Long
'''' Get number of characters in lpsz
cChars = lstrlenA(lpsz)
'''' Initialize string
LPSTRtoBSTR = String$(cChars, 0)
'''' Copy string
CopyMemory ByVal StrPtr(LPSTRtoBSTR), ByVal lpsz, cChars
'''' Convert to Unicode
LPSTRtoBSTR = Trim0(StrConv(LPSTRtoBSTR, vbUnicode))
End Function
上一页 [1] [2] [3] [4] [5] |