Hi everybody!
I'm working to a project formed by a c++ service and a c# graphic interface.
I have to share some classes and functions, then I wrote a c++ dll but I've problems to use it. I'll show my example code to require your help and understand how to resolve. Thanks
exampledll.cpp:
// exampledll.cpp
#define SHAREDLL __declspec(dllexport)
#include "exampledll.h"
class SHAREDLL Test{
int i;
Test();
int Function(int);
};
Test::Test(){
...
};
int Test::Function(int i){
return i+1;
};
//exampledll.h
#ifndef SHAREDLL
#define SHAREDLL __declspec(dllimport)
#endif
class SHAREDLL Test;
I obtain this warning but project is compiled:
class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'Test'
But if I try to import it in a c# project, I have problems.
If I try to add dll as reference:
"A reference to "..file.dll" could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component"
If I try directly to import the dll with:
[DllImport("file.dll", SetLastError = true)]
private static extern class Test;
- "Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'file.dll' or one of its dependencies"
- "The referenced component 'WifiMonitorDLL' could not be found. "
- "Error The modifier 'extern' is not valid for this item"