Marshalling double pointers in C#

49 views Asked by At

I have to interact with a provided C library where one of the functions is declared as follows:

int GetFileList(struct spiflash_file **ptr_spiflash_filelist, int **file_num);

where **ptr_spiflash_filelist is a pointer to a pointer that represent an array of spiflash_file structs, and **file_num is a pointer to a pointer of the total file counts.

I am having quite the trouble in marshalling those 2 parameters... This is what I came up with until now:

 [DllImport(LibName, SetLastError = true)]
 private static extern int GetFileList(out IntPtr ptr_spiflash_filelist, out IntPtr file_num);

This does not throw exceptions nor errors, but when I inspect the two variables I get absurd values ( i.e. on an empty flash the file count is 1790873936...)

I can't understand how to properly do it and it feels like I am missing just a couple steps..

0

There are 0 answers