R
Roy Chastain
I have a legacy application that currently loads an unmanaged (legacy) DLL via LoadLibrary, finds some entry points in it and then
calls them.
I would like to replace the unmanaged DLL with a managed DLL.
I have created a DLL with C++ that has the managed code. It also has unmanaged entry points that mirror the existing legacy DLL.
My problem is that I don't know how to transition to the managed code in this DLL.
I have found CorBindToRuntimeEx but that is as far as I have gotten.
My thinking is that it should go something like this
__gc class ManagedControl
{
public:
void Method1 (void);
void Method2 (void);
}
#pragma unmanaged
static gcroot<ManagedControl*> mc;
__declspec(dllexport) BOOL __stdcall umCreateControl (void)
{
HRESULT result;
ICorRuntimeHost *pHost = NULL;
result = CorBindToRuntimeEx(NULL,NULL,0,CLSID_CorRuntimeHost,IID_ICorRuntimeHost,(void **)&pHost);
/*
Do something to instantiate the managed class that represents the object being used
store that result in mc
*/
return TRUE;
}
Then in the other entry points I would 'simply' call the corresponding method on the managed class instance (mc)
hopefully by something that looks like
__declspec(dllexport) void__stdcall umMethod1 (void)
{
mc->Method1();
}
etc.
Thanks for getting me to the next step.
calls them.
I would like to replace the unmanaged DLL with a managed DLL.
I have created a DLL with C++ that has the managed code. It also has unmanaged entry points that mirror the existing legacy DLL.
My problem is that I don't know how to transition to the managed code in this DLL.
I have found CorBindToRuntimeEx but that is as far as I have gotten.
My thinking is that it should go something like this
__gc class ManagedControl
{
public:
void Method1 (void);
void Method2 (void);
}
#pragma unmanaged
static gcroot<ManagedControl*> mc;
__declspec(dllexport) BOOL __stdcall umCreateControl (void)
{
HRESULT result;
ICorRuntimeHost *pHost = NULL;
result = CorBindToRuntimeEx(NULL,NULL,0,CLSID_CorRuntimeHost,IID_ICorRuntimeHost,(void **)&pHost);
/*
Do something to instantiate the managed class that represents the object being used
store that result in mc
*/
return TRUE;
}
Then in the other entry points I would 'simply' call the corresponding method on the managed class instance (mc)
hopefully by something that looks like
__declspec(dllexport) void__stdcall umMethod1 (void)
{
mc->Method1();
}
etc.
Thanks for getting me to the next step.