2011年2月23日 星期三

vbnet 使用方式 VarPtr()

參考
--------
Imports System.Runtime.InteropServices

Public Class Form1

Public Data(40) As Byte

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(VarPtr(Data(0)))
End Sub

Public Function VarPtr(ByVal obj As Object) As Integer
Dim GC As GCHandle = GCHandle.Alloc(obj, GCHandleType.Pinned)
Return GC.AddrOfPinnedObject.ToInt32
GC.Free()
End Function

End Class

沒有留言:

張貼留言