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 andComVisibleAttribute .
Here is my code.
using System;
using System.Runtime.InteropServices;
namespace ClassLibrary2
{
[ClassInterfaceAttribute
(ClassInterfaceType.AutoDual),ComVisibleAttribute (true)]
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 makereference 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 inClassLibrary2.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.