Mihajlo Cvetanović
2010-01-20 10:50:29 UTC
I'm creating a C++ dll and C# code that uses it. At the moment (and
subject to change if there is better solution) functions in DLL have one
input and one output structure. Output structure has pointer to dynamic
byte array, like this:
struct DataBlock {
UCHAR* data;
int size;
}
struct Person {
wchar_t name[50];
int name_size;
wchar_t surname[50];
int surname_size;
}
bool WINAPI DeleteBlock(DataBlock* block);
bool WINAPI CreatePersonBlock(DataBlock* block, const Person* person);
bool WINAPI CreateOtherBlock(DataBlock* block, const Other* other);
Function DeleteBlock is supposed to delete arrays created from other
functions (maximum array size is unknown). If you have a suggestion how
to transfer data better, I'll gladly hear it.
My main question is how to marshal DataBlock? I'm new to C#, especially
to interop, but AFAIK marshaling implies that original structure is
temporary, which means there'll be memory leak and DeleteBlock is
useless. So, how would I go about this?
subject to change if there is better solution) functions in DLL have one
input and one output structure. Output structure has pointer to dynamic
byte array, like this:
struct DataBlock {
UCHAR* data;
int size;
}
struct Person {
wchar_t name[50];
int name_size;
wchar_t surname[50];
int surname_size;
}
bool WINAPI DeleteBlock(DataBlock* block);
bool WINAPI CreatePersonBlock(DataBlock* block, const Person* person);
bool WINAPI CreateOtherBlock(DataBlock* block, const Other* other);
Function DeleteBlock is supposed to delete arrays created from other
functions (maximum array size is unknown). If you have a suggestion how
to transfer data better, I'll gladly hear it.
My main question is how to marshal DataBlock? I'm new to C#, especially
to interop, but AFAIK marshaling implies that original structure is
temporary, which means there'll be memory leak and DeleteBlock is
useless. So, how would I go about this?