I want to dynamically load DLLs (created from VB) and instantiate a
class with a particular name, like "ProcessClass".
I am able to load the DLL and confirm there is a class by that name BUT
I can't seem to create it or call methods to this newly created
instance. I have the following code:
public class Script
{
[DllImport("oleaut32", CharSet=CharSet.Unicode)]
private extern static void LoadTypeLib(string dllFilePath, out
UCOMITypeLib typeLibrary);
UCOMITypeLib typeLibrary;
LoadTypeLib(dllName, out typeLibrary);
for (int i = 0; i < typeLibrary.GetTypeInfoCount(); i++)
{
typeLibrary.GetDocumentation(i, out typeName, out
typeDocumentation, out typeHelpContext, out typeHelpFile);
if (typeName == "ProcessClass")
{
UCOMITypeInfo typeInformation;
object classInstance;
typeLibrary.GetTypeInfo(i, out typeInformation);
typeInformation.CreateInstance(null, ref guidIUnknown, out
classInstance);
MethodInfo method = classType.GetMethod("DoSomething",
BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public
);
method.Invoke(classInstance, new object[0]);
}
}
}
Am I going down the wrong road? The class seems to be created without
exception, but the created instance doesn't seem to be bound properly
as I don't see any of the methods I'm looking for when I loop through!!
-Ray