COM Interop - using .NET component in VC6 client app 
Author Message
 COM Interop - using .NET component in VC6 client app

Hello,

I created a VB.NET data access layer which takes advantage of ADO.NET
features, and want to use this in my old VC6 client application.  (My old
DAL was written in VB6, so I rewrote it in VB.NET using DataSet stuff).

Question: how to get COM interop to work?  I tried the following which
doesn't work:
1)  regasm LtvRulesDal.dll /tlb:LtvRulesDALNet.tlb
2)  in my VC6 client app, I use #import LtvRulesDALNet.tlb

Problem: while the import is successful, the LtvRulesDALNet methods are all
invisible in the VC6 app.  I also tried creating a VB6 client, added a
reference to LtvRulesDALNet.tlb, and the methods weren't visible.

In my VB.NET project, functions are declared within a class as follows:
Public Shared Function IsMacroDefined(ByVal strMacro As String) As Boolean

Private Shared Sub LogMessage(ByVal strMessage As String)

Because they are Shared, I would expect them to be visible in the VC6 or VB6
client, but they are not.  Interestingly, there is one variable that is
visible in the VC6 and VB6 clients - the shared DataSet member (???)

So I'm trying to figure out why I can't see the Functions.  Do I need to
create an Interface for every method or something like that in VB.NET?
(i.e. some COM code that used to be hidden by VB6)?

Thanks in advance for your help -

Alex




Sat, 04 Dec 2004 13:19:35 GMT  
 COM Interop - using .NET component in VC6 client app
Alex,

Quote:
>Problem: while the import is successful, the LtvRulesDALNet methods are all
>invisible in the VC6 app.  I also tried creating a VB6 client, added a
>reference to LtvRulesDALNet.tlb, and the methods weren't visible.

Read about the ClassInterface attribute in the docs. With
ClassInterfaceType.AutoDispatch (the default), the exported interface
only supports late bound calls. It's better if yoou change to
ClassInterfaceType.None, and manually define the public interface as a
separate interface type.

Mattias

===
Mattias Sj?gren (VB MVP)

http://www.msjogren.net/dotnet/



Sat, 04 Dec 2004 18:23:51 GMT  
 COM Interop - using .NET component in VC6 client app
Mattias,

Thanks for the tip.  This worked, as follows:

1) Defined Interface for every method I wanted my .NET component to export
to the VB6 client, like this:
<InterfaceType(ComInterfaceType.InterfaceIsDual)> _

Public Interface ILtvRulesInterface

2) Added ClassInterface attribute to class definition as follows:

<ClassInterface(ClassInterfaceType.None), _

System.Runtime.InteropServices.ProgId("LtvRuleObj_NET.LtvRuleObj")> Public
Class LtvRuleObj : Implements ILtvRulesInterface

3) Created instance of .NET component in VB6 client as follows:
Dim myRules As LtvRulesDAL.ILtvRulesInterface

myRules = New LtvRulesDAL.LtvRuleObj()

Now all the methods are visible with IntelliSense because I'm using early
binding.  Party time!

----------------------------

Alex Bates
Software Engineer
http://batesmotel.homeip.net

Project Lifecycle:  SNAFU -> TARFU -> FUBAR

----------------------------


Quote:
> Alex,

> >Problem: while the import is successful, the LtvRulesDALNet methods are
all
> >invisible in the VC6 app.  I also tried creating a VB6 client, added a
> >reference to LtvRulesDALNet.tlb, and the methods weren't visible.

> Read about the ClassInterface attribute in the docs. With
> ClassInterfaceType.AutoDispatch (the default), the exported interface
> only supports late bound calls. It's better if yoou change to
> ClassInterfaceType.None, and manually define the public interface as a
> separate interface type.

> Mattias

> ===
> Mattias Sj?gren (VB MVP)

> http://www.msjogren.net/dotnet/



Sun, 05 Dec 2004 15:18:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem passing VB COM+ ASP Request object to .NET component System.Web.HTTPRequest through COM interop

2. Automation error referencing .net dll from com (com interop)

3. Severe VB.NET COM/.NET Interop Limitation

4. Passing structures from C++ app to a VB client app through Network connection using COM

5. Streamwriter component (com interop) not functioning as expected

6. Using the VC6 PROFILE with VB 6 COM objects

7. COM / .NET interop

8. VB.NET COM Interop -vs- VB6 ---- The Turtle And The Hare

9. .Net browser control wrapper...will there be one?, com interop is crap

10. .NET to COM Interop with VSS - Deployment Question

11. .net interop with COM

12. NET COM interop on CL

 

 
Powered by phpBB® Forum Software