Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2006

Tip: Looking for answers? Try searching our database.

Casting Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RC - 12 Apr 2006 04:41 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.