Hi,
I created a simple c++ dll (the header file is as below). I am trying to use the functions and methods of this dll in a PocketPC application written in c#.net. I can only import and use the getInt() function. When i tried to call the functions of the CCApp class, the PocketPC 2003 emulator return me a System.NotSupportedException. The reason may be that the constructor is not properly called. Can anyone know how to import the constructor of this c++ class to c#, as well as all of its functions and methods
#ifdef CAPP_EXPORTS
#define CAPP_API __declspec(dllexport)
#else
#define CAPP_API __declspec(dllimport)
#endif
class CAPP_API CCApp {
private:
int m_num;
public:
CCApp();
~CCApp();
int getNum() {return m_num; }
void setNum(int n) {m_num = n;}
};
extern "C" CAPP_API int getInt() {return 30; }
C# dllimport
[DllImport("CApp.dll", EntryPoint="#2")] // i use dumpbin to get the value of entry point
extern static IntPtr CCApp();
[DllImport("CApp.dll")]
extern static int getNum();
[DllImport("CApp.dll")]
extern static void setNum(int n);
[DllImport("CApp.dll")]
extern static int getInt();
Thanks a lot
Ares

dllimport c++ object to c#
Joao Cruz
Hi
Using C++ object from .NET CF is currently not possible. The required calling convention (ThisCall) is not supported.
Your best option is to create a "C" style wrapper API for your C++ classes.
Michael
Paps
Thanks for the advice, i tried the wrapper and it worked. It's pretty sad that the calling convention is not supported because i dont really want to write a whole wrapper class for a big sdk which is written in c++.
Ares