Import? System. Runtime. InteropServices? Must there be one here?
Public? Class? Form 1
Public? Structure? M Dian
Dim? x? As? integer
Dim? y? As? integer
End? structure
Private? Sub? Button 1_Click(ByVal? Sender? As? System. Object? ByVal? e? As? System. EventArgs)? Handle? Button 1. click
Dim? Me? As? Integer? =? 50
Dim? ai()? As? Integer? =? { 1,? 2,? 3,? 4,? 5}
Dim? Pi? As? IntPtr? =? GCHandle。 Alloc(i,GCHandleType。 Nailed). AddrOfPinnedObject()? Get a pointer to an integer variable?
Dim? Pie? As? IntPtr? =? GCHandle。 Alloc(ai,GCHandleType。 Nailed). AddrOfPinnedObject()? Gets a pointer to the first address of an integer array.
MsgBox (marshaling. ReadInt32(pi,? 0))? Read back the value of the pointer to an integer variable.
MsgBox (marshaling. ReadInt32(pai,? 0? *? 4))? Reads back the first element of the array.
MsgBox (marshaling. ReadInt32(pai,? 1? *? 4))? Reads back the second element of the array.
MsgBox (marshaling. ReadInt32(pai,? 2? *? 4))? Reads back the third element of the array.
-here's the structure.
Dim? m_p? As? New? M Dian
m_p.x? =? 100
m_p.y? =? 50
Dim? pm_p? As? IntPtr? =? GCHandle。 Alloc(m_p,? GCHandleType。 Nailed). AddrOfPinnedObject()? Get the structure header address pointer?
MsgBox (marshaling. ReadInt32(pm_p,? 0? *? 4))? Reads back the first value of the structure.
MsgBox (marshaling. ReadInt32(pm_p,? 1? *? 4))? Reads back the second value of the structure.
End? submarine
End? classes