Ragazzi devo usare questa API in VB.net poichè sto trasportando il progetto dal VB6
nel codice esiste la struttura:codice:Private Declare Function waveInGetDevCaps Lib "winmm" Alias "waveInGetDevCapsA" (ByVal uDeviceID As Long, ByVal WaveInCapsPointer As Long, ByVal WaveInCapsStructSize As Long) As Long
nel codice usavo VarPtr per ottenere il puntatore di "caps" (struttura sopra):codice:Private Structure WaveInCaps Public ManufacturerID As Integer Public ProductID As Integer Public DriverVersion As Long Public ProductName() As Byte Public Formats As Long Public Channels As Integer Public Reserved As Integer End Structure
codice:waveInGetDevCaps(1, VarPtr(caps), Len(caps))
Ora su VB.net come posso ottenere l'indirizzo della variabile?
Ho provato con GCHandle sostituendo la vecchia varptr:
e durante l'esecuzione alla riga:codice:Public Shared Function VarPtr(ByVal o As Object) As Long Dim gh As GCHandle = GCHandle.Alloc(o, GCHandleType.Pinned) Dim gh2 As Long = gh.AddrOfPinnedObject.ToInt32 gh.Free() Return gh2 End Function
ottengocodice:Dim gh As GCHandle = GCHandle.Alloc(o, GCHandleType.Pinned)
"L'oggetto contiene dati non copiabili o non primitivi."
Non so come risolvere...

Rispondi quotando