C# interop - passing array of struct to a DLL.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,

Ive been looking for some assistance on this all day with no luck, so any pointers would be helpful.

struct SID_SEARCH_RESULT_DATA
{
   ULONG ulFieldID;
   USHORT usFieldLength;
   char szFieldData[FIELD_LENGTH];
};

I want to pass this from a c# app into an unmanaged c++ dll and populate it. Ive tried a couple of things but with no joy - can anyone give me an idea of the c++ exported method signature and the c# extern method declaration required to pass an array of this struct and populate it?

The main complication is that I wont know how many results I will have up front, so I need to be able to assign sufficient memory on the c++ dll side.

Any help would be hugely appreciated.

Thanks , Lee.

Edit: The C++ dll is not a COM object or anything similar, just a straight DLL. Thats why I want to do this via p/invoke and some sort of marshalling wizardry. As you may be able to tell, this has landed on my desk with an urgent sticker on it and Im new to c# & .NET, so I just need to get it working.

View the full article
 
Back
Top