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.

COM Interop - Interface Questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JerryWEC - 24 Jan 2007 23:26 GMT
Hey guys,

I'm trying to get Com Interop to work for my class library I have wrote. It
works fairly good for .net clients as is.  So now I'm trying to add a COM
Wrapper for it to expose it to a VB6 client.  I have discover the best way
to do this is to use the following attribute and an Interface to my base
class. This exposes my base class methods, properties and events to my
COM/VB6 client application.

<ClassInterface(ClassInterfaceType.None)> _

I have to use this because most of my code is in the base class called
Logging and I don't want to rewrite it again for COM so I'm figuring I can
use Inheritance and modify (override) the methods that need changed for VB6.
I'll override these methods in the ComLogging wrapper class I'm exposing to
the COM world.

One question I have is can I create one Interface called IStandardLogging
for my methods in the base class that are not changing and have another
Interface called IComLogging to expose my modified methods? I'm thinking I
can use the following ComSourceInterfaces() attribute to create the required
interface methods in the .tlb type library for VB6?

<ComSourceInterfaces(GetType(ILogging), GetType(IComLogging))> _

Another question I have is how do you expose the events in COM using the
above method suggested? Do you do them like the other Sub/Functions? Or, is
there more to it?

TIA! JerryM
Walter Wang [MSFT] - 26 Jan 2007 06:29 GMT
Hi Jerry,

Sorry for late reply.

I have reviewed all your posts about COM interop. It seems your objective
is to be able to use the Logging class both in .NET client and COM client.
Since you have the source code, I think you may not have to create a
wrapper for it. Why not make the data types used in the class compatible
for both types of clients? I mean, previously I suggested to create a
wrapper class because you mentioned that some data types are not
recogonized by VB6. However, a wrapper class works best when you only need
to expose some static/shared functions or you don't have the source code of
the original class.

Regarding the ComSourceInterfaces attribute, you're right it's used to
expose events to COM client, we have a How-To in MSDN library:

#How to: Raise Events Handled by a COM Sink
http://msdn2.microsoft.com/en-us/library/dd8bf0x3.aspx

By the way, your several posts about COM interop seems a bit scattered and
I'm not sure about some posts' status. Would you please summarize all the
blocking issues you're having now and post them here, so that we can focus
in one thread and have better context to reference. Thanks.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
JerryWEC - 26 Jan 2007 15:05 GMT
Walter,

There is basically what I was originally trying to do or accomplish...

Objective: Inherit from my base class called logging and create my new class
called ComLogging (COM Wrapper).

I have found two good web pages that explain how COM Interop works and why
it works that way it does.  So I'm a lot smarter now.

Basically, I was planning to inherit from my base class and leave it along
(works for .net clients) and then in the derived class (Com Wrapper) I could
modify my properies, subs/functions, and events to work with VB6 (COM).

I have still thinking along those lines, but I have changes three of my
public properties in the base class from .net Long datatypes to .net
Integers (long in VB6).  One of my event have a .net exception object (which
VB6 can't understand).  So I was planning on overriding my properties,
methods, and events in the derived class (COM wrapper) to make them work
with VB6.

One of the two good web pages told me how to do COM interop (the preferred
way) and not the canned out of the box way that the COM templete provides.

I'll start a new post after I play with this some more.
Thanks! JerryM

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.