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..
out refseems to be the correct way, but it ouputs garbage data.unsafecode an option here? i.e.private static unsafe extern int GetFileList(ptr_spiflash_filelist** ptr_spiflash_filelist, int** file_num);? Usage would be something likeptr_spiflash_filelist* ptr = null; int* file_num = null; GetFileList(&ptr, &file_num);, which should leave the two locals initialized