I have a dll written by VB6 and I've use "tlbimp" command to produce an
interop assembly.
I now try to use reflexion to create an object from VB6 DLL to .NET
environment and cast it back (eg. ClassA)
Actually, it's a portion of an ASP.NET application. The DLLs were places
under "\bin" folder. I've tried running it on 2 machines both are XP
Professional IIS installed with .NET Framwwork 2.0. However, I found there
is a casting error on 1 of machine and other one works fine.
Object _com_obj = Activator.CreateInstance(t); //where t is the type get
from Assembly Object
MethodInfo mInfo = t.GetMethod("get_GenObject");
object[] param = new object[]{1,2,3,4,5};
Object _obj = mInfo.Invoke(_com_obj, param); //both machines can get object
reference, the object type is "System.__ComObject"
ClassA _oClassA = _obj as ClassA; //<---Casting is invalid on 1 machine
How to fix the casting problem? Any Missing Library required?
Is there any possible ways to find the actual type of _obj instead of
"System.__ComObject"?
Best Regards,
RC
Dmytro Lapshyn [MVP] - 12 Apr 2006 13:44 GMT
Hi,
First of all, please make sure you properly register the VB6 DLL on the
machine where it is giving you trouble. For COM DLLs, it is definitely not
enough to just copy them. Registration is usually mandatory, at least it is
in your case. Use the regsvr32 tool to register the VB6 DLL.
>I have a dll written by VB6 and I've use "tlbimp" command to produce an
>interop assembly.
[quoted text clipped - 22 lines]
> Best Regards,
> RC
RC - 13 Apr 2006 02:56 GMT
Hi,
But I am sure the dll is already registered.
BR,
RC
> Hi,
>
[quoted text clipped - 29 lines]
>> Best Regards,
>> RC
Dmytro Lapshyn [MVP] - 13 Apr 2006 10:43 GMT
Let me then ask you this: why don't you use an interop library and
instantiate the COM object through the CoClass wrapper supplied in the
interop library? Using the Activator class is kludgy after all. And you
shouldn't have any casting problems with the interop library.
> Hi,
>
[quoted text clipped - 36 lines]
>>> Best Regards,
>>> RC