I have an unmanaged (C/C++) DLL which I need to call from a C# application.
The DLL call needs to return data (from a C++ class that is created by the DLL) to the C# application.
I have control over the DLL’s exported function, so I can create a wrapper around the C++ class if necessary. I know how to access the DLL with p/Invoke, so I’m just looking for some guidance on how to return the data.
The data that is received from the DLL is a series of key-value pairs, so I was thinking about returning a JSON string and deserializing it to an object with Json.NET.
What is the preferred way to access this type of data from an unmanaged source from a C#/.NET application?
If you’re able to modify the C++ DLL then C++/CLI could be cleanest. You’ll be able to write a set of .NET wrapper classes directly in C++, avoiding the need to write separate P/Invoke declarations.