DLL Callback

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nigel Walton

    #1

    DLL Callback

    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(L ayoutKind.Seque ntial)_
    Public Structure PutSampProc2
    <MarshalAs(Unma nagedType.ByVal Array,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(L ayoutKind.Seque ntial)_
    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 ***
  • Mattias Sjögren

    #2
    Re: DLL Callback

    Nigel,
    >This is the original struct in c:
    >
    >typedef void (*PutSampProc)( short samples[], int arraylen, int
    >nrsamples,vo id *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.

    Comment

    • Nigel Devon

      #3
      Re: DLL Callback

      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((NrSa mples * 2) - 1)
      Marshal.Copy(Sa mples, 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 ***

      Comment

      Working...