Exporting c++ DLL including Classes into c# project

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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'

Did I wrong something?
Last edited on
Did I wrong something?
No, not really.

http://www.cplusplus.com/forum/general/78467/#msg423146
Ok, thanks.. it works importing to a c++ project

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"

I haven't used C# for a while, so I can't remember the details. But I did find this link that you may find helpful.
http://msdn.microsoft.com/en-us/library/ms235281%28v=vs.80%29.aspx
Ok, thanks kbw.. I resolved with Wrappers!
Last edited on
Topic archived. No new replies allowed.