I have some of unmanaged C++ dynamic library and C# GUI application, using it. I need to pass a pointer to structure with embedded buffer and some integral meta data members. Structure allocated on C# side to C++ library. Then library populates it, returns to C# application and application uses it in some ways, releasing finally.
My first approach was using StringBuilder as embedded string buffer, but i receive an exception on runtime which says it is not allowed to use StringBuilder as structure member. Also I got advice to use string preinited with suitable buffer size. I've tryed this approach, but it seems bufefr passed via string cannot be modified on C++ part. Is it right?
// C++ typedef struct SomeStruct{ wchar_t* stringBuffer; // buffer uint64_t size; // some additional integral fields int64_t mTime; // some additional integral fields }; // Native library API method MYCDLL_API uint8_t __stdcall getSomeStructures(uint32_t index, SomeStruct* struct, uint64_t stringBufferSize); // C# part [DllImport(myLibraryname, CallingConvention = CallingConvention.StdCall)] static extern RetCode getSomeStructures(UInt32 index, ref SomeStruct someStruct, UInt64 stringBufferSize); How this task could be solved? As, I mentioned I need to pass a reference to structure with embedded modifyable character buffer from C# to C++.