Following is a self referential struct from C++
typedef struct _FCV
{
unsigned long ulID;
unsigned long ulVersion;
unsigned long ulStatus;
unsigned long ulSize;
struct _FCV* pNext;
} FCV;
I need to use PInvoke to translate to C# struct, What is the "pNext" i should declare? Thank you.
You have perhaps reached the point where p/invoke is not the best tool for the job. The complexity here may make a C++/CLI layer a more attractive option.
With p/invoke you'd need to declare the
pNext
field asIntPtr
. Then you'd need to populate one instance of the struct for each item in the linked list. Finally you'd need to walk through the list assigning topNext
. That will require you to pin each struct withGCHandle.Alloc
and then get the pinned address withAddrOfPinnedObject
. Once the call has been made you then need to destroy all theGCHandle
objects to un-pin the structs.So it's possible to do, but the code may be rather unwieldy, and may not be particularly efficient. You should seriously consider C++/CLI instead.