vb.net - Passing VB Callback function to C dll - noob is stuck -


Callback in VB (from CDLL).

I have to pass a VB function as a callback for AC function in DLL I know that I need to use the address for the function, but how much do I have to do it as I am more confusing.

  PaError Pa_OpenStream (PaStream ** Section, Constraints PaStreamParameters * inputParameters, Constants PaStreamParameters * OutputParameters, Double sampleRate, Unsigned long framesPerBuffer , PaStreamFlags: m to have a callback address defined in C as Streamflags, Pasteum Callback * Stream Callback, Zero * User Data);  

While the function parameter is 7, * the stream callback type PaStreamCallback defines thusly:

  typedef int PaStreamCallback (static zero * input, zero * output) , Unsigned long frameCount, constant PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, Zero * UserData);  

I have in my vb project:

  Private publicity function Pa_OpenStream Lib "portaudio_x86.dll" _ (ByVal section as IntPtr _, ByVal _InputParameters as IntPtr, ByVal outputParameters PaStreamParameters as _ _, ByVal as samprate double, byVal as FPB double _, ByVal paClipoff as Long _, ByVal patestCallBack IntPtr _, ByVal as Data IntPtr) As an integer  as 

(do not worry if I have incorrectly described some other parameters, then I come to them later I now focus on callback.)

I callback function in module 1.vb:

function MyCallback (ByVal inp byte, _ ByVal outp byte In the form of _byVal framecount long, _ ByVal as pastreamcallbacktimeinfo byte, _ ByVal as pastreamcallbackflags byte, _byVal as userdata byte) as the integer 'clever things end here function

In Dll it is called

with the external function

, _ Clipoff, _ address, MyCallback, _dataptr)

This external function is broken in announcing - it does not like IntPtr as a function indicator for address type.

Can anyone show me how to implement this callback function to pass?

Many thanks David

This MSDN article will help:

< / Div>

Comments