Home All Groups Group Topic Archive Search About
Author
12 Jul 2006 2:51 AM
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


*** Sent via Developersdex http://www.developersdex.com ***

Author
12 Jul 2006 6:09 AM
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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
27 Jul 2006 1:34 PM
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

*** Sent via Developersdex http://www.developersdex.com ***