Hello NG,
I'm having to use a function in an external library that returns a pointer
to an array of structs.
The function declaration according to library vendor is:
device** getList( int &count)
The returned structs:
typedef struct tag_dev
{
int nr;
char* name;
} device;
I tried coding this:
[DllImport("myDll.dll")]
private static extern device** getList(int* count);
...
...
unsafe static void getDeviceList()
{
int count;
int* p = &count;
device** devices = getList(p);
..
..
}
This compiles without errors (unsafe flag set) and there are no runtime
errors.
But the result is nonsense. There is always just one entrance in the list,
18 are expected,
the nr member of the struct is always zero and the name pointer points to
nothing meaningful.
I think, my declaration for the return value is wrong, isn't it? Do I have
to use unsafe code at all
to invoke the external function or are there other ways to do this?
Thanks for any ideas,
regards Uwe
|