Accessing from VB6

  • Thread starter Thread starter Chris Fellows
  • Start date Start date
C

Chris Fellows

I have a C# class (.NET 2003) that I need to access from a VB6 EXE. Can
someone tell me what I need to do to make this possible? Do I have to
define the class as an interface and also set ComVisible(True)?
 
Chris,

That's not all you will have to do. You will also have to create a GUID
for your interface, and your class and make sure that the interface is
implemented on the class. However, you pretty much have it down (you also
have to perform registration of the class for COM with regasm as well).

You might want to check out the section of the MSDN documentation titled
"Exposing .NET Framework Components to COM ", located at:

http://msdn2.microsoft.com/en-us/library/zsfww439.aspx

It should give you everything you need to expose your .NET types to COM
properly.

Hope this helps.
 
Hi,

Chris Fellows said:
I have a C# class (.NET 2003) that I need to access from a VB6 EXE. Can
someone tell me what I need to do to make this possible? Do I have to
define the class as an interface and also set ComVisible(True)?

You do not need to define an interface, all you need to do is declare the
..dll as "registered for COM interop" , you find this in the property
project/build section.
 
He could do that, but this is really a bad idea given the demand for
immutable interface definitions in COM. Without specifying the interface,
any changes that he makes to his class could potentially break the clients
that are using his components.
 
Nicholas Paldino said:
He could do that, but this is really a bad idea given the demand for immutable
interface definitions in COM. Without specifying the interface, any changes that he makes
to his class could potentially break the clients that are using his components.

Absolutely right, if you want to expose your classes to COM clients you better know what
your clients are expecting, don't blindly assume that the defaults are what the client
expects from a server. Or otherwise stated - define your classes as COM friendly as
possible.


Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top