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 / March 2008

Tip: Looking for answers? Try searching our database.

Using reflection on VB6 Collections

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tschulken - 01 Mar 2008 03:11 GMT
I am working on a conversion project from VB6 -> .Net. The first pass
is to just convert over w/o restructuring any of the classes. For
testing of the business object classes, I am writing a .Net utlility
to instantiate the VB6 objects, use reflection on them to get their
property values. I will then do the same against the converted .Net
classes to ensure all results are the same.

It seems I have no problems going down a object heirarchy unless the
property is of type collection. If the property is another object, no
problem.

When I run into a collection class, I cast like this (note: prop is of
type PropertyInfo):
Dim aList As VBA.Collection = CType(prop.GetValue(Source, Nothing),
VBA.Collection)

I then try and iterate through the collection using reflection but all
it says
       For Each item In aList
            Dim aType As Type = CType(item , Object).GetType
            Dim aPropInfo() As PropertyInfo = aType.GetProperties
       Next

When I get the type info from the item in the collection, all it says
is: {System.__ComObject} and has no additional information for me to
use.

Is there a way to get the information from a VBA Collection class
using reflection?

Tim
Jeroen Mostert - 01 Mar 2008 10:29 GMT
> I am working on a conversion project from VB6 -> .Net. The first pass
> is to just convert over w/o restructuring any of the classes. For
[quoted text clipped - 22 lines]
> is: {System.__ComObject} and has no additional information for me to
> use.

__ComObject is a proxy wrapping around the actual class. In order to do
anything meaningful with the object, you must cast it to a specific type
(not Object), which will retrieve the proper interface in the background.
See http://support.microsoft.com/kb/320523

However, you don't know an actual type in this case. There is a helper
method that will retrieve an actual type by going through IDispatch,
Microsoft.VisualBasic.Information.TypeName(). You could use that to
dynamically cast, like this:

Dim typeName As String = Information.TypeName(item)
CType(item, Type.GetType(typeName))

Disclaimer: I have no idea if this actually works and I can't test it. It
will at least require that all VB6 types you encounter have been imported
into .NET.

Signature

J.

> Is there a way to get the information from a VBA Collection class
> using reflection?
>
> Tim
tschulken - 04 Mar 2008 05:26 GMT
Thanks for the reply, in theory that looked like it would work
unfortunatly it seems that the GetType does not work off of COM
objects. I was wondering if anyone else knew of a way to get the Type
information of an COM object using a prog id.

I did try using:
Dim comProgType As Type =
Type.GetTypeFromProgID("ComCollectionTest.Person")

My comProgType object ends up being "FullName = "System.__ComObject".
Even though I have a reference to ComCollectionTest.Person and can
early bind to it.

Any help would be appreciated.

Tim
Willy Denoyette [MVP] - 04 Mar 2008 08:49 GMT
> Thanks for the reply, in theory that looked like it would work
> unfortunatly it seems that the GetType does not work off of COM
[quoted text clipped - 12 lines]
>
> Tim

System.__ComObject is a generic wrapper, that means a RCW that does not
carry any metadata other than it's own.
The reason for this is simple, by calling Type.GetTypeFromProgID, you are
ignoring the imported metadata from the interop assembly, in order to get at
the type info you will have to cast the generic wrapper to the type
ComCollectionTest.Person.

Willy.
tschulken - 04 Mar 2008 19:54 GMT
On Mar 4, 3:49 am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.be> wrote:

> > Thanks for the reply, in theory that looked like it would work
> > unfortunatly it seems that the GetType does not work off of COM
[quoted text clipped - 23 lines]
>
> - Show quoted text -

Thanks Willy. The problem is when i am using reflection, when I run
into the VBA.Collections I don't get the type information for the
items inside. I can get a string representation of the type name
(Information.TypeName). I was wondering if I could get the type info
using that string typename. I am writing a utility to get all of the
property values of my COM objects. When I run into objects inside the
collection, I can't get the type info to get the properties, to get
their values.

I have the references to the com dll's but there are a ton of classes
that I wanted to do all of this dynamically.

Any additional hlep would be appreciated (i.e. is there another way to
get the property values when I don't have the type info?)

Tim

Rate this thread:







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.