VB6 and C# interface inheritance

  • Thread starter Thread starter Roy Pereira
  • Start date Start date
R

Roy Pereira

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....
 
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....
.
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.
 
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/default.asp?url=/library/en-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/default.asp?url=/library/en-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" <[email protected]>
Sender: "Roy Pereira" <[email protected]>
References: <[email protected]>
Subject: RE: VB6 and C# interface inheritance
Date: Wed, 20 Aug 2003 07:53:07 -0700
Lines: 174
Message-ID: <[email protected]>
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" <[email protected]>
Sender: "Roy Pereira" <[email protected]>
References: <[email protected]>
Subject: VB6 and C# interface inheritance
Date: Tue, 19 Aug 2003 05:40:19 -0700
Lines: 31
Message-ID: <[email protected]>
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.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 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.


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.
 
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 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/default.asp? url=/library/en-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/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 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" <[email protected]>
Sender: "Roy Pereira" <[email protected]>
References: <[email protected]>
Subject: RE: VB6 and C# interface inheritance
Date: Wed, 20 Aug 2003 07:53:07 -0700
Lines: 174
Message-ID: <[email protected]>
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" <[email protected]>
Sender: "Roy Pereira" <[email protected]>
References: <[email protected]>
Subject: VB6 and C# interface inheritance
Date: Tue, 19 Aug 2003 05:40:19 -0700
Lines: 31
Message-ID: <[email protected]>
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.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 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.



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.

.
 
Back
Top