Marching an int class pointer between C ++ and C #

I have an ActiveX control (written in C ++) and refer to its RCW builds (created by aximp.exe) from a C # project.

In C ++ code that implements the Ax control, I have a class that implements an interface that displays as a property of the Ax control.

Looking at the created RCW builds, I can see the interface. And I can try to declare a variable of my type.

Now, if I only have a pointer to an instance of a C ++ class that implements an in-memory interface, can it be marshaled into a C # managed object representing the interface using this pointer?

Please note that this is not an interface pointer. This is a pointer to an instance of the class that I have.

+3
source share
2 answers

You can try C ++ / CLI. Writing code that interacts between C ++ and C # is fast.

+1
source

I think there are two questions here.

Can you marshal the "this" pointer to managed code, but not as a specific interface

Yes. This is possible by implementing a COM interface in a C # application, and then passing "this" as one of the parameters. The managed type accepting the "this" pointer must be Int32 or Int64 (unsigned OK) depending on your platform

Can I do something useful with this pointer

Yes and No.

- , , . COM-.

, "C" , . # PInvoke

++

void SomeType_SomeMethod(SomeType* pSomeType) {
  pSomeType->SomeMethod();
}

#

[DllImport("YourDll.dll")]
public static extern void SomeType_SomeMethod(IntPtr pSomeType);
+1

Source: https://habr.com/ru/post/1713422/


All Articles