3

How to convert this c++ struct into C# equivalent?

typedef struct readdirplus_hash_bucket {
     ifs_rdplusbucket **hash;
     int hash_size;
} ifs_rdplushashbucket;

I stuck in double pointer. Thanks in advance.

ulughbekula
  • 371
  • 1
  • 3
  • 12
  • 3
    Do you want to pass this struct to unmanaged code using p/invoke, or are you trying to rewrite some code in C#? What does the pointer to pointer mean; is it a pointer to an array, an array of pointers, ...? – dtb May 07 '13 at 08:16
  • Yes, I have to pass this struct to unmanaged code. ifs_rdplusbucket itself is a struct. – ulughbekula May 07 '13 at 08:21
  • You need to post native C code which shows, how this structure is used. Without these additional details, the only thing that I can say is: hash variable must have IntPtr type, use Marshal.PtrToStructure method to convert it to ifs_rdplusbucket. – Alex F May 07 '13 at 08:26
  • Have you declared the c# equivalent of `ifs_rdplusbucket`? – Jodrell May 07 '13 at 08:28
  • Yes. ifs_rdplusbucket is declared. In case of it was a pointer, I would just declare it as "public IntPtr hash" and convert it back to ifs_rdplusbucket using Marshal.PtrToStructure. But, I am concerned about double pointer, where it is not allowed to use out or ref keyword when declaring a struct. – ulughbekula May 07 '13 at 08:34
  • 1
    Double pointer is also IntPtr. Possibly it points to another IntPtr, which points to ifs_rdplusbucket. Use Marhal.ReadIntPtr and then Marshal.PtrToStructure to dereference IntPtr twice. – Alex F May 07 '13 at 08:42

0 Answers0