• 9
• 10
• 10
• 11
• 17

[c# to c++]send array of structures

This topic is 595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

hello.
I would send some array of primitive structures from c# to c++.
1)marshaling
2)cli c++ .net dll wrapper
3)?other technology

what are the pro and cons?
only a base Then I do an full search on google.
thanks.

Share on other sites

Depending of your project the answer o this mayvary. Lets assume you have a c++/cli project then doing this would be simpler than with c++ itself where marshalling (and also other c++/cli related technics) may cause some production overhead.

Lets assume you are plain c++ then you could serialize you structs if they are such simple as you say. A related function would look like this

__declspec(dllexport) void GetStructArray(byte* toCopyTo)
{
}


and on your c# side you'll do

[DllImport("Your.dll")]
public static extern void nativeGetStructArray
(
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)]
byte[] data
}


and deserialize them after you got them