c++-clinativedllimportmixed-mode

How to export a native class from a dll (namely a protobuf generated class)


I'm trying to write a wrapper dll in C++/CLI to use some native classes in c#.

For Testing I created another C++/CLI Project that consumes the dll.

My Problem is, that I would like to use one of the native classes in the dll project in the test project, but the linker complains that it does not find the symbols for this class members. I guess it's because the native class is not defined ref public. As the native class code is auto generated by the Google Protobuffers compiler I can not add ref public to it.

Don't misunderstand me, I don't want to use this native class in the future c# project but I want to directly access it in the Test project.


Solution

  • I think you have to follow the typical native c++ way of doing this: export the class from the dll, link against the dll from the test project, and then #include the header file from the test project where you need to use the class.

    I don't think there is a "managed way" to reference and use a native class (hopefully others will correct me if I'm wrong).