Question

Greetings, I am sorry for bothering, I'll show the question:

I am trying to export some functions written in c++ in a DLL in order to import them in a C# Application running on Visual Studio. I make the export as reported in the following code,

tobeexported.h:

namespace SOMENAMESPACE
{
                class __declspec(dllexport) SOMECLASS
                {
                               public: 
                               SOMETYPE func(param A,char b[tot]);

                };
}

tobeexported.cpp:

#include "stdafx.h"
#include "tobeexported.h"
...


using namespace SOMENAMESPACE;

SOMETYPE SOMECLASS:: func(param A,char b[tot])
                {
                               ...some stuff inside...
                }

The dll is righly created and the code is already CLR-managed(looked with a disassembling software(reflector)) and contains the exported functions then I "Add the Reference" in my c# application and the dll is found, but when I open it with the object browser it is completely empty, neither class, nor object has been exported and ready to be used

can you help me please? thanks best regards

Was it helpful?

Solution

What about using managed C++ to compile your DLL? Then you just have to add a ref to the class like this:

namespace SOMENAMESPACE
{
                public ref class SOMECLASS
                {
                               public: 
                               SOMETYPE func(param A,char b[tot]);

                };
}

After successful compilation and referencing in the other project, the class should be visible. Exporting native C++ is not really portable, each compiler produces different results and is tedious to bind from within C#...

EDIT: added public access modifier to ref class...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top