export function with clr parameters from dll?

前端 未结 1 624
南方客
南方客 2021-01-21 11:08

I\'ve got a legacy managed c++ dll, and I need to call some function which is returning a managed type.

For dllexports without managed types, this is easy, I just define

1条回答
  •  失恋的感觉
    2021-01-21 11:44

    It has to be an assembly, there's no other way to build code with a managed type like that. Mixing managed and native code in one assembly is fine. Which automatically solves the problem, the function will be available in the metadata, no need to export it. You need to drop all the decoration, it cannot be applied to a managed method. And it should be in a ref class to allow other managed languages to use it.

    public ref class Mumble {
    public:
        static System::Collections::Generic::List^  InitSystem();
    };
    

    A C# program now can use var lst = Mumble.InitSystem(). Using a namespace is recommended.

    Watch out for /clr btw, it will readily convert native code to IL without complaint. Either turn off /clr on a source code file or use #pragma managed.

    0 讨论(0)
提交回复
热议问题