All pastes #483049 Raw Edit

Stuff

public text v1 · immutable
·published 2007-05-11 15:23 UTC
rendered paste body
.h file
------

class MyThing {

 public:
	MyThing();
	void Insert(int a);
	int Get();
	~MyThing();
}



.cpp file
------
// make sure the .dll for the  
declspec(DLLEXPORT) void *MyThing_Create(void) {
	MyClass *p = new MyClass();
        return p;
}

declspec(DLLEXPORT) void MyThing_Insert(void *InstancePtr,int a) {
	MyClass *p = (MyClass *) InstancePtr;
        p->Insert(a);
}

declspec(DLLEXPORT) int MyThing_Get(void *InstancePtr) {
	MyClass *p = (MyClass *) InstancePtr
        return p->Get();
}

declsepc(DLLEXPORT) void MyThing_Delete(void *instancePtr) {
      MyClass *p = (MyClass *) InstancePtr;
      delete p;
}

.cs file
--------
[DllImport("MyClass.dll", EntryPoint="Insert", ExactSpelling=false,
			 SetLastError=true)]
		static extern void MyThingInsert(
			[MarshalAs(UnmanagedType.IntPtr] IntPtr InstancePtr,
			[MarshalAs(UnmanagedType.Int32] Int32 data);


// etc for each one of these

then make a class like this

class MyThing {
	private IntPtr instanceptr;

	public MyThing() {
		instanceptr = MyThing_Create();
	}

	public Insert(int data) {
		MyThing_Insert(instanceptr,data);
	}

// and so on

}