不能直接使用CopyMemoryStr,应该将字符串转为byte数组,然后使用CopyMemory
Property Get item() As String
If h = 0 Then ErrRaise ERROR_INVALID_DATA
'BugAssert p <> pNull
Dim c As Long,ptr0 As Long
Dim ab() As Byte
'取出BSTR的长度
CopyMemory c,ByVal p,4
If c > 0 Then
ReDim ab(c - 1)
CopyMemory ByVal VarPtr(ab(0)),ByVal (p + 4),c
item = ab
End If
End Property
Property Let item(s As String) If h = 0 Then ErrRaise ERROR_INVALID_DATA 'BugAssert p <> pNull Dim c As Long Dim ab() As Byte c = LenB(s) ab = s ' 重新将BSTR放回内存中 CopyMemory ByVal p,c,4 CopyMemory ByVal (p + 4),ByVal VarPtr(ab(0)),cEnd Property