Skwerl
10/18/2007 7:58:00 PM
I am writing a native C++ plug-in for a program that will act as an interface
for managed code. My managed code needs to be able to call methods in an
active instance of the native plug-in running in its host program. Is the
following the best way (or even possible) to accomplish this?
1. Plug-in host program loads native plug-in.
2. Plug-in calls method in managed.dll, passing a function pointer
(&this->UnmanagedMethod) to ManagedClass.ManagedMethod(IntPtr funcPtr).
3. ManagedClass creates DelegateFromFuncPtr from function pointer and stores
it in class instance.
4. Managed class calls DelegateFromFuncPtr as necessary to communicate with
native plug-in instance.
If I'm going about this in a legitimate way, I'm having a hard time handing
the function pointer to the managed class. The compiler gives me a 2664
error because it won't allow me to cast a function pointer to a long (which
is what the CCW is asking for as an IntPtr). Any suggestions? Thanks in
advance.
//Native code sections
HRESULT __stdcall CVDJPlug::OnLoad()
{
//Initialize COM object
VDJCom::_VDJ *com_ptr;
CoInitialize(NULL);
VDJCom::_VDJPtr p(__uuidof(VDJCom::VDJ));
com_ptr = p;
//Give the managed class a pointer to a method in this class
instance
com_ptr->SetInfoPointer(&CVDJPlug::GetInfoMiddle);
return 0;
}
//The native member function
void CVDJPlug::GetInfoMiddle(char*, void*)
{
....
}