R
Richard de Beer
Hi,
I've got some old code(VB6) which has been upgraded to VB.net.
In the old code, the undocumented function "VarPtr" is used. But in VB.net,
this function is no longer supported. I've searched the internet and found
some code withch should solve the problem.
This is the code:
Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
But this code generates an error:
"An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll Additional information: Object contains non-primitive or
non-blittable data."
Since I'm a beginner, I was hoping that you could help me with this problem.
Thanks a lot!
I've got some old code(VB6) which has been upgraded to VB.net.
In the old code, the undocumented function "VarPtr" is used. But in VB.net,
this function is no longer supported. I've searched the internet and found
some code withch should solve the problem.
This is the code:
Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
But this code generates an error:
"An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll Additional information: Object contains non-primitive or
non-blittable data."
Since I'm a beginner, I was hoping that you could help me with this problem.
Thanks a lot!