2

The API reference in question is located here.

I need to know how to properly DLLImport and then use this in vb:

const bctbx_list_t* linphone_core_get_calls (   LinphoneCore *  lc  )   

The part I'm having trouble with is the const bctbx_list_t* return value. I tried declaring the dllimport like this:

<DllImport(LIBNAME, CallingConvention:=CallingConvention.Cdecl)>
Private Shared Function linphone_core_get_calls(lc As IntPtr) As List(Of IntPtr)
End Function

and then using it like this:

Dim CurrentCallList As List(Of IntPtr) = linphone_core_get_calls(_LinPhoneCore)

which compiles but gives me an error:

Cannot marshal 'return value': Generic types cannot be marshaled.

Any help would be greatly appreciated.

GSerg
  • 76,472
  • 17
  • 159
  • 346
Sam Hall
  • 31
  • 3
  • Why do you think `bctbx_list_t` is the same as .NET's `List`? It's almost certainly not; find where the `bctbx_list_t` type is defined and see how to better declare it. If it's an opaque object, declare it as `IntPtr`. – GSerg Jan 13 '17 at 21:01
  • @GSerg Thank you. – Sam Hall Jan 14 '17 at 15:32

1 Answers1

1

Based on GSerg's comment, I went looking for the definition of bctbx_list_t, which I found here. It's a linked list:

typedef struct _bctbx_list {
    struct _bctbx_list *next;
    struct _bctbx_list *prev;
    void *data;
} bctbx_list_t;

I translated that to:

Private Structure _bctbx_list
    Public [next] As IntPtr
    Public prev As IntPtr
    Public data As IntPtr
End Structure

changing the import to:

<DllImport(LIBNAME, CallingConvention:=CallingConvention.Cdecl)>
Private Shared Function linphone_core_get_calls(lc As IntPtr) As _bctbx_list
End Function

And I'm in business.

Sam Hall
  • 31
  • 3