DLL Callback

N

Nigel Walton

I am trying to read some data from a dll via a callback. I have a
deligate and all imformation is correct except for an array.

This is the original struct in c:

typedef void (*PutSampProc)(short samples[], int arraylen, int
nrsamples,void *userData);

This does not work:

<StructLayout(LayoutKind.Sequential)> _
Public Structure PutSampProc2
<MarshalAs(UnmanagedType.ByValArray,SizeConst:=1024)> _
Dim Samples() As Short
Dim ArrayLen As Integer
Dim NrSamples As Integer
Dim Userdata As Byte
End Structure

This gives the correct data for ArrayLen, NrSamples and Userdata, but
just a value for the Samples():

<StructLayout(LayoutKind.Sequential)> _
Public Structure PutSampProc
Dim Samples As Integer
Dim ArrayLen As Integer
Dim NrSamples As Integer
Dim Userdata As Byte
End Structure

What am I doing wrong????

Please help

Nigel
 
M

Mattias Sjögren

Nigel,
This is the original struct in c:

typedef void (*PutSampProc)(short samples[], int arraylen, int
nrsamples,void *userData);

This is not a struct declaration, it's a function pointer type.


Mattias
 
N

Nigel Devon

I now have it working like this:

Private Sub SampProc(ByVal Samples As Integer, ByVal ArrayLen As
Integer, ByVal NrSamples As Integer, ByVal UserData As Byte)
ReDim MySamples((NrSamples * 2) - 1)
Marshal.Copy(Samples, MySamples, 0, NrSamples * 2)

Is it possible to receive 'Samples' as an array. Do I have to add some
marshalling code to my delegate?

Nigel
 

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