Dear Chris Taylor,
I tried this, supposing I used VC++ to create an OCX call MyOCX, and there
is a object in the OCX call MyObject. I used the AxImp.exe to generate the
proxy assembly call MyOCXLib.dll. Now in my code
Assembly myAssembly = Assembly.LoadFrom("MyOCXLib.dll");
Type myObjType = myAssembly.GetType("MyOCXLib.MyObject");
MyOCXLib.MyObject myObj =
(MyOCXLib.MyObject)Activator.CreateInstance(myObjType);
// the above line will cause an exception to be thorwn with error message
"specified cast in invalid"
// If I change to the following line
MyOCXLib.MyObject myObj =
(MyOCXLib.MyObject)Activator.CreateInstance(typeof(MyOCXLib.MyObject));
// then it is ok.
that is the problem. do you know why? I think the MyOCXLib.MyObject type
does not exist in the current Assembly. What do you think?
Regards,
ZhangZQ