My problem is with understanding the finer point of mixed langage programming and accessing API's in external libraries. My skills at C++ are nonexistent and at VB, mediocre.
I have a c++ dll compiled (portaudio library), and am trying to access it from VB (Visual Studio 2005). I am getting MarshallDirectiveException errors when calling a function, I believe because I am interacting incorrectly with the dll.
the C++ function and structures are defined as follows:
header info:
typedef int PaHostApiIndex;
...
typedef double PaTime;
...
typedef struct PaDeviceInfo
{
int structVersion; /* this is struct version 2 */
const char *name;
PaHostApiIndex hostApi; /* note this is a host API index, not a type id*/
int maxInputChannels;
int maxOutputChannels;
PaTime defaultLowInputLatency;
PaTime defaultLowOutputLatency;
PaTime defaultHighInputLatency;
PaTime defaultHighOutputLatency;
double defaultSampleRate;
} PaDeviceInfo;
...
const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device );
program usage from docs:
const PaDeviceInfo* Pa_GetDeviceInfo ( PaDeviceIndex device ) Retrieve a pointer to a PaDeviceInfo structure containing information about the specified device.
Returns: A pointer to an immutable PaDeviceInfo structure. If the device parameter is out of range the function returns NULL.
Parameters: device A valid device index in the range 0 to (Pa_GetDeviceCount()-1)
...
in the VB program I have:
Private Declare Function Pa_GetDeviceInfo Lib "portaudio_x86.dll" (ByVal dindex As Integer) As PaDeviceInfo
...
Private Structure PaDeviceInfo
Dim structVersion As Integer
<MarshalAs(Runtime.InteropServices.UnmanagedType.LPStr)> Dim name As String
Dim hostapi As Integer
Dim maxInputChannels As Integer
Dim maxOutputChannels As Integer
Dim defaultLowInputLatency As Double
Dim defaultLowOutputLatency As Double
Dim defaultHighInputLatency As Double
Dim defaultHighOutputLatency As Double
Dim defaultSampleRate As Double
End Structure
...
Dim di As New PaDeviceInfo
di = Pa_GetDeviceInfo(outputParameters.device)
This feels wrong as docs state Pa_GetDeviceInfo returns a POINTER to a structure containing info about the structure, implying function creates the structure initially.
I am completely new to mixed language programming, a c++ utter noob, and a poor VB programmer. Can anyone guide me in the correct way to attack this problem ? My feeling is that I need to understand how to get VB to reference a struct in memry created in the dll, so I need to get vb to understand 'pointer to thing' as a function return.
Much appreciation for any assistance rendered. Please don't just say rtfm, I'm up to my eyes in FM's at the minute, I just don't know where to look.
Many thanks, David