lundi 2 mars 2015

Convert C# string to C++ WCHAR* over COM


I have a COM local server (implemented in C++) which I am trying to call from C# code. The method that's giving me trouble looks like this:



HRESULT Foo([in] const WCHAR* bar);


The parameter shows up in on the C# side as a ref ushort, but I want to pass a string to the method, not a number. What is the best way to make this method accept a string?


I see other answers which describe DllImporting the function and then using [MarshalAs(UnmanagedType.LPWStr)] on the parameter, but since the COM server is running as a local server (meaning it's a standalone exe instead of a dll), and it's part of an interface, I don't think I can DllImport it. Do I need to do something with the server's proxy dll instead?




Aucun commentaire:

Enregistrer un commentaire