473,378 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

VB6 and C# interface inheritance

I have an application that is composed of a set
of "Content" dlls and a viewer application. The viewer
calls a standard set of functions that are present in all
the dlls. I maintain this by making my contnent dlls
implement an interface created in vb6. The viewer
application is bound to this interface. This way, I am
able to add Content without redeploying the dlls (I just
have to add the new dlls). I want to write new content
for this application in C#, but I don't want to rewrite
the existing content dlls. I have two questions:
1. Can I inherit and implement the same vb6 interface
from C#? How?
2. If I write a new interface in C#, is there anyway for
v6 developers to inherit from this interface? How?
Thanks for any help....
Jul 19 '05 #1
4 8141
SR
Hi
1. Can I inherit and implement the same vb6 interface
from C#? How?
You can do that without any problems. You just need to
use COM Interop and import the interface in your .Net
project(If you are using VS.Net then Add Reference->COM
Tab-> Select the COM Library). This will create .Net
wrappers for the COM Components. Then you can use them
just as you would use .Net interfaces
2. If I write a new interface in C#, is there anyway for
v6 developers to inherit from this interface? How?
This again is no problem coz of InterOp. You can use the
tlbexp command line tool to export your .Net assemblies to
Com as COM Wrappers. This is the reverse of 1. mentioned
above. Once you use the export you wil get COM DLLs
(wrappers to be precise and you can reference them in your
VB6 projects)

hth

regards,

sr
Thanks for any help....
regards,

sr

-----Original Message-----
I have an application that is composed of a set
of "Content" dlls and a viewer application. The viewer
calls a standard set of functions that are present in all
the dlls. I maintain this by making my contnent dlls
implement an interface created in vb6. The viewer
application is bound to this interface. This way, I am
able to add Content without redeploying the dlls (I just
have to add the new dlls). I want to write new content
for this application in C#, but I don't want to rewrite
the existing content dlls. I have two questions:
1. Can I inherit and implement the same vb6 interface
from C#? How?
2. If I write a new interface in C#, is there anyway for
v6 developers to inherit from this interface? How?
Thanks for any help....
.

Jul 19 '05 #2
-----Original Message-----
I have an application that is composed of a set
of "Content" dlls and a viewer application. The viewer
calls a standard set of functions that are present in all
the dlls. I maintain this by making my contnent dlls
implement an interface created in vb6. The viewer
application is bound to this interface. This way, I am
able to add Content without redeploying the dlls (I just
have to add the new dlls). I want to write new content
for this application in C#, but I don't want to rewrite
the existing content dlls. I have two questions:
1. Can I inherit and implement the same vb6 interface
from C#? How?
2. If I write a new interface in C#, is there anyway for
v6 developers to inherit from this interface? How?
Thanks for any help....
.

Thanks,
I managed to create a .net interface and it is exposed
through COM. However, I have run into another issue. I
have created a .net class that implements the interface,
and I want to expose this class to COM. However, I can't
declare the implemented interface methods as public. How
can I expose the methods in my class so they can be called
from a COM client? The docs I have read say that the
public keyword cannot be used for interfaces even in the
implementation. They also say that for COM to create the
CCW, only public methods are exposed. Please advise.
Thanks.
Jul 19 '05 #3
Hi Roy,

1. Did you mean that you declare a interface in .NET and implement it in
NET and then exposed it to COM?
using System;
using System.Runtime.InteropServices;
namespace ComTest
{
public interface IGMD
{
string Draw(string strcfgxml);
}
public class TestEquip:IGMD
{
public string Draw(string strcfgxml)
{
string blah = "Hello";
return blah;
}
}
}
If I compile the code listed above, and regasm it, I can access it from a
VB client or a .NET client.
Regasm ComTest.dll /tlb:ComTest.tlb

[VB Client][Make a reference to the ComTest.tlb
Private Sub Command1_Click()
Dim o As ComTest.IGMD
Set o = New ComTest.TestEquip
MsgBox o.Draw("")
End Sub

Here is a link about exposed exposing .NET Framework Components to COM.
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconexposingnetframeworkcomponentstocom.asp
2.The code you mention in your code.
public class TestEquip:IGMD
{
string IIApp.IGMD.Draw(string xmlcfg)
{
string blah = "Hello";
return blah;
}
}

It is "Explicit Interface Member Implementation", which can not have a
public or private access modifier. Here is a link about "Explicit Interface
Member Implementation"
http://msdn.microsoft.com/library/de...us/csspec/html
/vclrfcsharpspec_13_4_1.asp
3.
[ClassInterfaceAttributClassInterfaceType.AutoDual) ,ComVisibleAttribute(true
)]
Yes, usually ComVisibleAttribute is not needed. From your last post you can
not access the method of the interface, so I hope you can declare it
explicitly to narrow down the issue more quickly.

Please feel free to let me know if you have further question related.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security

--------------------
Content-Class: urn:content-classes:message
From: "Roy Pereira" <ro*********@siemens.com>
Sender: "Roy Pereira" <ro*********@siemens.com>
References: <01****************************@phx.gbl> <0d****************************@phx.gbl>
<ll**************@cpmsftngxa06.phx.gbl>Subject: RE: VB6 and C# interface inheritance
Date: Wed, 20 Aug 2003 07:53:07 -0700
Lines: 174
Message-ID: <0e****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNnKsSHMOKlTTxrSTOGFC88GFDkHg==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:105183
NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
X-Tomcat-NG: microsoft.public.dotnet.general

Thanks...
But my problem is a little different. I have the
following interface I created in .NET and also registered
for use in COM.
public interface IGMD
{
string Draw(string strcfgxml);
}
This function draw is inherited by either a VB6 client or
another C# client in the form of a dll. .NET client
example:
[ClassInterface(ClassInterfaceType.AutoDual)]
public class TestEquip:IGMD
{
string IIApp.IGMD.Draw(string xmlcfg)
{
string blah = "Hello";
return blah;
}
}
This dll is the one I want to expose to COM as well.
However, I cannot use the public keyword for this function
as I get the following error:-Compiler Error CS0106.
I did a little more research into this, and found that I
can create a redundant function with the same method
signature and expose that one as public (interface
mapping). e.g.
public string Draw(string xmlcfg)
{
string blah = "Hello Again";
return blah;
}
When I compile this and register it, I am able to call
this function and it returns "Hello", not "Hello again"
which means the interface method, not the public method is
called. This solution is acceptable, but is it good
design? Do I need to interface map all the funtions I am
doing interface inheritance on? Please advise...Thanks.
Also, what does the
[ClassInterfaceAttributClassInterfaceType.AutoDual) ,ComVisi
bleAttribute(true)]
do as opposed to just using
[ClassInterfaceAttributClassInterfaceType.AutoDual)]?
-----Original Message-----
Hi Roy,

You may try the Interop Attributes :

ClassInterfaceAttribute and
ComVisibleAttribute .
Here is my code.
using System;
using System.Runtime.InteropServices;
namespace ClassLibrary2
{

[ClassInterfaceAttribute

(ClassInterfaceType.AutoDual),ComVisibleAttribute (tr
ue)]
public class CCLookup : TestComInt.ILookup
{
public CCLookup()
{
;
}
public object GetByEmail(string strEmail)
{
return "email";
}
public object GetByID(int lngID)
{
return "id";
}
}
}

Then you can use the tool regasm to exports the tlb file.
regasm ClassLibrary2.dll /tlb:ClassLibrary2.tlb

Now you can use the ClassLibrary2.dll as a common COM

object when you make
reference to the ClassLibrary2.tlb.
[NOTE: you may need to copy the ClassLibrary2.dll and
Interop.TestComInt.dll to same directory as the your

client exe lies.]
[TestComInt.dll is a COM whose interface was implemented

by you in
ClassLibrary2.dll]
Please have a try and let me know if this does the job

for you.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and

confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Roy Pereira" <ro*********@siemens.com>
Sender: "Roy Pereira" <ro*********@siemens.com>
References: <01****************************@phx.gbl>
Subject: VB6 and C# interface inheritance
Date: Tue, 19 Aug 2003 05:40:19 -0700
Lines: 31
Message-ID: <0d****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNmTwyz+iIFLEcRTcaO+CtymcMS/A==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gblmicrosoft.public.dotnet.general:104996NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general
-----Original Message-----
I have an application that is composed of a set
of "Content" dlls and a viewer application. The viewer
calls a standard set of functions that are present inallthe dlls. I maintain this by making my contnent dlls
implement an interface created in vb6. The viewer
application is bound to this interface. This way, I am
able to add Content without redeploying the dlls (Ijusthave to add the new dlls). I want to write new content
for this application in C#, but I don't want to rewrite
the existing content dlls. I have two questions:
1. Can I inherit and implement the same vb6 interface
from C#? How?
2. If I write a new interface in C#, is there anywayforv6 developers to inherit from this interface? How?
Thanks for any help....
.

Thanks,
I managed to create a .net interface and it is exposed
through COM. However, I have run into another issue. I
have created a .net class that implements the interface,
and I want to expose this class to COM. However, Ican'tdeclare the implemented interface methods as public.Howcan I expose the methods in my class so they can becalledfrom a COM client? The docs I have read say that the
public keyword cannot be used for interfaces even in the
implementation. They also say that for COM to createtheCCW, only public methods are exposed. Please advise.
Thanks.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and

confers no rights.

.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 19 '05 #4
Thank you!! The key was I was not grasping the difference
between Explicit Interface inheritance and implicit
interface inheritance. I come from a vb6 background and
was assuming that explicit was the only way to go. Thanks
again...
-----Original Message-----
Hi Roy,

1. Did you mean that you declare a interface in .NET and implement it in.NET and then exposed it to COM?
using System;
using System.Runtime.InteropServices;
namespace ComTest
{
public interface IGMD
{
string Draw(string strcfgxml);
}
public class TestEquip:IGMD
{
public string Draw(string strcfgxml)
{
string blah = "Hello";
return blah;
}
}
}
If I compile the code listed above, and regasm it, I can access it from aVB client or a .NET client.
Regasm ComTest.dll /tlb:ComTest.tlb

[VB Client][Make a reference to the ComTest.tlb
Private Sub Command1_Click()
Dim o As ComTest.IGMD
Set o = New ComTest.TestEquip
MsgBox o.Draw("")
End Sub

Here is a link about exposed exposing .NET Framework Components to COM.http://msdn.microsoft.com/library/default.asp? url=/library/en-us/cpguide/html/cpconexposingnetframeworkcomponentstocom.asp
2.The code you mention in your code.
public class TestEquip:IGMD
{
string IIApp.IGMD.Draw(string xmlcfg)
{
string blah = "Hello";
return blah;
}
}

It is "Explicit Interface Member Implementation", which can not have apublic or private access modifier. Here is a link about "Explicit InterfaceMember Implementation"
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/csspec/html/vclrfcsharpspec_13_4_1.asp
3.
[ClassInterfaceAttributClassInterfaceType.AutoDual) ,ComVisi
bleAttribute(true)]
Yes, usually ComVisibleAttribute is not needed. From your last post you cannot access the method of the interface, so I hope you can declare itexplicitly to narrow down the issue more quickly.

Please feel free to let me know if you have further question related.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security

--------------------
Content-Class: urn:content-classes:message
From: "Roy Pereira" <ro*********@siemens.com>
Sender: "Roy Pereira" <ro*********@siemens.com>
References: <01****************************@phx.gbl><0d****************************@phx.gbl>
<ll**************@cpmsftngxa06.phx.gbl>
Subject: RE: VB6 and C# interface inheritance
Date: Wed, 20 Aug 2003 07:53:07 -0700
Lines: 174
Message-ID: <0e****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNnKsSHMOKlTTxrSTOGFC88GFDkHg==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:105183NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
X-Tomcat-NG: microsoft.public.dotnet.general

Thanks...
But my problem is a little different. I have the
following interface I created in .NET and also registeredfor use in COM.
public interface IGMD
{
string Draw(string strcfgxml);
}
This function draw is inherited by either a VB6 client oranother C# client in the form of a dll. .NET client
example:
[ClassInterface(ClassInterfaceType.AutoDual)]
public class TestEquip:IGMD
{
string IIApp.IGMD.Draw(string xmlcfg)
{
string blah = "Hello";
return blah;
}
}
This dll is the one I want to expose to COM as well.
However, I cannot use the public keyword for this functionas I get the following error:-Compiler Error CS0106.
I did a little more research into this, and found that I
can create a redundant function with the same method
signature and expose that one as public (interface
mapping). e.g.
public string Draw(string xmlcfg)
{
string blah = "Hello Again";
return blah;
}
When I compile this and register it, I am able to call
this function and it returns "Hello", not "Hello again"
which means the interface method, not the public method iscalled. This solution is acceptable, but is it good
design? Do I need to interface map all the funtions I amdoing interface inheritance on? Please advise...Thanks.
Also, what does the
[ClassInterfaceAttributClassInterfaceType.AutoDual) ,ComVisibleAttribute(true)]
do as opposed to just using
[ClassInterfaceAttributClassInterfaceType.AutoDual)]?
-----Original Message-----
Hi Roy,

You may try the Interop Attributes :

ClassInterfaceAttribute and
ComVisibleAttribute .
Here is my code.
using System;
using System.Runtime.InteropServices;
namespace ClassLibrary2
{

[ClassInterfaceAttribute

(ClassInterfaceType.AutoDual),ComVisibleAttribut e(tr
ue)]
public class CCLookup : TestComInt.ILookup
{
public CCLookup()
{
;
}
public object GetByEmail(string strEmail)
{
return "email";
}
public object GetByID(int lngID)
{
return "id";
}
}
}

Then you can use the tool regasm to exports the tlb file.regasm ClassLibrary2.dll /tlb:ClassLibrary2.tlb

Now you can use the ClassLibrary2.dll as a common COM

object when you make
reference to the ClassLibrary2.tlb.
[NOTE: you may need to copy the ClassLibrary2.dll and
Interop.TestComInt.dll to same directory as the your

client exe lies.]
[TestComInt.dll is a COM whose interface was implemented
by you in
ClassLibrary2.dll]
Please have a try and let me know if this does the job

for you.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and

confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Roy Pereira" <ro*********@siemens.com>
Sender: "Roy Pereira" <ro*********@siemens.com>
References: <01****************************@phx.gbl>
Subject: VB6 and C# interface inheritance
Date: Tue, 19 Aug 2003 05:40:19 -0700
Lines: 31
Message-ID: <0d****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNmTwyz+iIFLEcRTcaO+CtymcMS/A==
X-MimeOLE: Produced By Microsoft MimeOLE

V5.50.4910.0300Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl

microsoft.public.dotnet.general:104996
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general
>-----Original Message-----
>I have an application that is composed of a set
>of "Content" dlls and a viewer application. The viewer>calls a standard set of functions that are present in

all
>the dlls. I maintain this by making my contnent dlls
>implement an interface created in vb6. The viewer
>application is bound to this interface. This way, I am>able to add Content without redeploying the dlls (I

just
>have to add the new dlls). I want to write new content>for this application in C#, but I don't want to rewrite>the existing content dlls. I have two questions:
>1. Can I inherit and implement the same vb6 interface>from C#? How?
>2. If I write a new interface in C#, is there anyway

for
>v6 developers to inherit from this interface? How?
>Thanks for any help....
>.
>
Thanks,
I managed to create a .net interface and it is exposedthrough COM. However, I have run into another issue. Ihave created a .net class that implements the interface,and I want to expose this class to COM. However, I

can't
declare the implemented interface methods as public.

How
can I expose the methods in my class so they can be

called
from a COM client? The docs I have read say that the
public keyword cannot be used for interfaces even in theimplementation. They also say that for COM to create

the
CCW, only public methods are exposed. Please advise.
Thanks.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and

confers no rights.

.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and

confers no rights.
.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Tom Evans | last post by:
My basic question: If I have a specific interface which I know is going to be implemented by a number of classes, but there is no implementation commonality between them, what is the preferred...
4
by: christopher diggins | last post by:
A feature that I find signficantly missing in C# is the ability to write functions in interfaces that can call other functions of the interface. Given an interface ISomeInteface the only way we can...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
7
by: Hazz | last post by:
Are there any good references/articles/books which provide clarity toward my insecurity still on deciding how to model a complex system? I still feel uncomfortable with my understanding, even...
10
by: Brett | last post by:
I'm still trying to figure out concrete reasons to use one over the other. I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract...
6
by: John Salerno | last post by:
I understand how they work (basically), but I think maybe the examples I'm reading are too elementary to really show their value. Here's one from Programming C#: #region Using directives ...
12
by: Meya-awe | last post by:
I am puzzled, what is the purpose of an interface? How does it work, what i mean is how does the compiler treats this? Why when we talk about separating user interface from business logic, an...
6
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
4
by: Raja Chandrasekaran | last post by:
Hai friends, I really wonder, If the interface does not have any definition, Y do we need to use interface. You can then only we can use Multiple inheritance. I really cant understand, Just for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.