Unmanaged C++ Void*

F

Frustrated

I have a C++ DLL that I need to access from VB.NET. The function I am
trying to call is declared like this:

void* PASCAL iidc_lockdata( HIIDC, long frame = -1 )

This function returns a pointer to unsigned chars

I am able to find the size of the array out. It is usually 128800 to
use as an example if it helps.

I have declared the interface for my VB.NET as follows:

Private Declare Function _iidc_lockdata Lib "iidcapi_SONY.dll" Alias
"#37" (ByVal HIIDC As Int32, ByVal frame As Int32) As
System.Runtime.InteropServices.GCHandle

and also I have tried it as

Private Declare Function _iidc_lockdata Lib "iidcapi_SONY.dll" Alias
"#37" (ByVal HIIDC As Int32, ByVal frame As Int32) As IntPtr

(1) My first question is, how do I declare the function, should I use
GCHandle or IntPtr or something else?

As far as calling the function goes, I have tried this:

Dim gch As System.Runtime.InteropServices.GCHandle
gch = New System.Runtime.InteropServices.GCHandle
Dim lBufSz As Int32 = camera.currentDataFrameBytes(m_hCamera)
gch.Alloc(lBufSz)
Try
gch = camera.lockdata(m_hCamera, -1)
gch.Free()
Catch ex As Exception
MsgBox(ex.Message)
End Try

FYI the function camera.lockdata is a mapped function and it is as
follows:

Public Function lockdata(ByVal HIIDC As Int32, ByVal frame As Int32)
As System.Runtime.InteropServices.GCHandle
Return _iidc_lockdata(HIIDC, frame)
End Function


and I get "Object reference not set to an instance of an object"

(2) How would I get the data?

I have been really struggling with this.

Thanks,
Mike Dixon
 
M

Mattias Sjögren

Mike,
(1) My first question is, how do I declare the function, should I use
GCHandle or IntPtr or something else?
IntPtr


(2) How would I get the data?

System.Runtime.InteropServices.Marshal.Copy



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top