Hi guys ...
I have written a C++ managed class library DLL and a simple app to use this managed DLL. In order to use this class I have started as follows :
Assembly *asm = Assembly::LoadFrom("D:\Test\tester.DLL");
Type *asmTypes = asm->GetTypes();
for (int i = 0; i <= asmTypes->Count - 1; i++)
if (asmTypes[i]->GetInterface("IRequiredObject") != NULL)
Object *TestObject = Activator::CreateInstance(asmTypes[i]);
IRequiredInterface *reqInt = dynamic_cast<IRequiredInterface *>(TestObject);
Note that IRequiredInterface was defined in a shared header file that both the DLL and the EXE share - Mistake 1 ...
Although the intellisence now gives me the methods in IRequiredInterface eg :
The dynamic_cast operation fails at runtime and returns NULL.
I know that I can use late binding to export each of the methods 1 by 1 from the DLL :
MethodInfo *MyMethod1 = asmTypes[i]->GetMethod("IRequiredMethod1");
Object *tmpObj = MyMethod1->Invoke(TestObject , NULL);
The problem I face here is the number of methods that are required, multiplied by a selection of different DLL's makes late binding an ugly solution.
My question : After retrieving a class from a managed DLL, is it possible to instantiate it and then make method calls from it, without late-binding, so using it is almost like using a normal (local) class ?
Any help here is greatly appreciated ...