Marshal.PtrToStringAnsi(pOutputformat)
is the best that you can do. There's no avoiding that. If you try to marshal as out string OutputFormat
then the marshaller will call CoTaskMemFree
on the pointer returned by the native code. And that ends in tears.
The question remains as to who is responsible for deallocating the memory that pOutputformat
points to? Only you can know the answer to that.
One wonders why the designer of this COM interface chose to use C strings rather than the COM BSTR
.