views:

55

answers:

1

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

+1  A: 

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...

jdehaan
Thanks for answer,I am using managed c++ (in Visual Studio the project that contains c++ code is a “class library”) but even with “ref” command instead of export it works, the given result is completely the same.[The operation of importing is possible even because I previously imported a c++ dll; I created my new dll really similar to the working one but nothing good happens^^] Thanks again
Ricibald
Oh sorry, I forgot to tell you to add also public, `public ref class ...`. I hope then that it will work fine. In the .NET reflector the visibility is probably private or internal am I right?
jdehaan
it works! thanks!
Ricibald