Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Returning Buffer from C to C#

$
0
0
I don’t C# very often. I have a C function that takes a byte array as input and should return a string it generates internally. Just for starters I generate the string and discard it since I don’t know how to return it to C#. In C I have this: int __stdcall ConvertHodgmanKylotanjbadamsfrobRavyneApochPiQSeanMiddleditchrip_offspaceratLightness1024_to_String(const char * thoseGuys); In C# I have this: [DllImport("Important.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] private static extern unsafe Int32 ConvertHodgmanKylotanjbadamsfrobRavyneApochPiQSeanMiddleditchrip_offspaceratLightness1024_to_String(byte [] thoseGuys); I step into ConvertHodgmanKylotanjbadamsfrobRavyneApochPiQSeanMiddleditchrip_offspaceratLightness1024_to_String() and on the C side it works fine. It generates the output I want as a local so I can verify it and then discards it to avoid leaking. I need it to return the generated string to C#. Let’s say I want this to be the final C function: int __stdcall ConvertHodgmanKylotanjbadamsfrobRavyneApochPiQSeanMiddleditchrip_offspaceratLightness1024_to_String(const char * thoseGuys, char * retVal, int &retLen); How should I allocate it in C and how do I tell C# how to treat it as a parameter and how do I deallocate it after? L. Spiro

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>