473,395 Members | 1,969 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,395 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 8143
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.