Answer the question
In order to leave comments, you need to log in
How to call a given function from an assembly in managed c++?
There is an assembly in C#, which has a public method that accepts System.Object, treating it like a COM object.
From C#, this method is used like this:
var ComType = Type.GetTypeFromProgID("Excel.Application");
var obj = Activator.CreateInstance(ComType);
ProcessObject(obj); // ProcessObject(System.Object objToProcess)
MyClass::MyMethod(IDispatch* pDesigner)
{
// здесь должен быть вызов функции ProcessObject
// из сборки на С# с передачей туда указателя pDesigner
}
Answer the question
In order to leave comments, you need to log in
The toaster is traditionally bad with specific answers. Only reasoning about "you are doing it wrong"
Here is a specific answer, in case it is useful to someone:
// IUnknown* pDesigner
IntPtr handle = IntPtr(pDesigner);
Object^ managedObject = System::Runtime::InteropServices::Marshal::GetObjectForIUnknown(handle);
In general, read about Ole Automation first. For your task, you are using slightly the wrong thing. Then look at how it's done in .NET, there are tools out there. I did it myself in C ++ and C #, so in C ++ it's hell, it's better not to go there. But in C#, everything is fine, you don’t even have to think about COM, Ole in general.
UPD. At first I cheated with the version, it was on .net 1.1.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question