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 / January 2007

Tip: Looking for answers? Try searching our database.

Using reflection on Interop activex-dll object?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cit42@web.de - 25 Jan 2007 10:12 GMT
Hello,
I want to write a unittest that compares
the property-values of a managed-object with
the property-values of an object instantiated via interop.

Background is:
I have a vb6-class with many public properties. The properties will be
filled by a Read-method from a file and can be written to a file by a
write-method.
Then I converted the vb6-code with upgrade-wizard to VB.NET.

Now I want a use case that instantiates these two classes,
the "old" via interop and the "new" one.
Then get via reflection the propertynames and values, interate about
them and compare the values.
The managed part is no problem with reflection, but

the first problem was that the activeX-instance does not have the
GetType() method.
Ok ... then I found this posting:

http://groups.google.de/group/microsoft.public.dotnet.framework/browse_thread/th
read/10c9516762808b3d/52447f5e8683c33d?lnk=st&q=createinstance+interop+oMethod&r
num=1&hl=de#52447f5e8683c33d


With that idea I tried:

oAssembly = oAssembly.LoadFrom("Interop.TestObject06.dll")
oObj =
Activator.CreateInstance(oAssembly.GetType("TestObject06.CTestObject06Class"))

There is the problem that CreateInstance throws a
MissingMethodException and tells
that it cannot create an instance of an interface.

Mhmmm... Then I tried:
oObj =
Activator.CreateInstance(oAssembly.GetType("TestObject06.CTestObject06Class"),
BindingFlags.IgnoreReturn)

There is the problem that CreateInstance throws also a
MissingMethodException and tells
that that the constructor for "TestObject06.CTestObject06Class" cannot
be found.

I suppose  "constructor" means in this case:

Public Sub Class_Initialize()
End Sub

But this piece of code is in in the vb6.class.

........

Now i am a bit confused.

Is it possible to get the properties of an activex-dll via interop?

Thanks
 Gordian
Mattias Sjögren - 25 Jan 2007 18:54 GMT
>oAssembly = oAssembly.LoadFrom("Interop.TestObject06.dll")
>oObj =
[quoted text clipped - 3 lines]
>MissingMethodException and tells
>that it cannot create an instance of an interface.

The typelib importer creates an interface with the same name as the
imported coclass, and then a class with "Class" appended to the name.
So try oAssembly.GetType("TestObject06.CTestObject06ClassClass")

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

cit42@web.de - 26 Jan 2007 07:39 GMT
> imported coclass, and then a class with "Class" appended to the name.
> So try oAssembly.GetType("TestObject06.CTestObject06ClassClass")

That's it!

I didn't notice the postfix "Class" and its meaning.
Now it works.

Thank You
 Gordian

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.