您需要首先确定哪些Guid
类可供您使用,如果它们不提供从指针接收 GUID 的方法,但确实使用Byte
.NET 之类的数组Guid
,那么您需要将Marshal.Copy
调用转换为MemCpy
使用
Declare Sub MemCpy Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination() As Byte, ByVal SourcePtr As Long, ByVal Length As Long)
注意我已经调整了MemCpy
声明以期望指针已经转换为 aLong
并复制到Byte
数组。
因此,您的代码可能是(但请记住,我还没有检查Guid
您可以使用哪些类):
Private Function SYS_GuidPtrToGuid(ByVal p As Long) As Guid
Dim b(15) As Byte
MemCpy b, p, UBound(b) - LBound(b) + 1
SYS_GuidPtrToGuid = New Guid(b)
End Function
鉴于您的评论,这里是从指针直接MemCpy
复制到 a 的声明。Long
guid
Declare Sub MemCpy Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As GUID, ByVal SourcePtr As Long, ByVal Length As Long)
现在调用很简单:
Private Function SYS_GuidPtrToGuid(ByVal p As Long) As Guid
MemCpy SYS_GuidPtrToGuid, p, 16
End Function
这确实取决于guid
包装是否正确,但这就是Type
.