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))
上一页 [1] [2] [3] [4] [5]
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18