Can you change the function signature to allow you alloc and pass the buffer to the function… then management is all yours.
From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Greg Keogh Sent: Tuesday, 24 October 2017 4:15 PM To: ozDotNet <ozdotnet@ozdotnet.com> Subject: Marshalling strings Folks, my REST web service makes calls to C++ functions in a native DLL. The functions return wchar_t* which I marshal into a managed string. The author of the C++ code doesn't know when to free the buffer he's allocated for the string (neither do I). The very last statement in his function is return char_ptr, so the function ends and the buffer becomes a leak. I consume the pointer after his function ends, so when can he delete it? Is there some trick I'm forgetting? Or are we doing it the wrong way? Greg K