Jump to content
  • Advertisement
Sign in to follow this  
giugio1977

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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)
{
   //write your serializer code here
}

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

Share this post


Link to post
Share on other sites
You could simply pass a pointer and even use a std::vector to stay flexible on the size of the array (/vector)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!