[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

VB6 app interop with VB.NET dll

Dan Vice

2/21/2007 10:37:00 PM

I'm having some issues I hope someone can assist me with.

I have a VB6 application which needs to interact with a VB.NET
assembly (dll). The VB6 application is being developed on a separate
PC from my .NET development PC. I have setup the .NET assembly for
COM interop and have given it a strong name (this is all done with VS
2005). I have also copied the DLL to the C:\windows\assembly folder on
the VB6 PC which adds it to the GAC. When I create an instance of the
dll in VB6:

Global x as Test_Client.Client (this is actually in a Module)
Set x = New Test_Client.Client

and then access a function in the DLL:

If x.TestFunction() = True then....

It all seems to work pretty well. However, I'm seeing some wierd
things when I update the .NET dll, rebuild it, and re-deploy it to the
VB6 machine. Sometimes, my parameters don't show up in the VB6
intellisense. Sometimes, my boolean functions won't give me the
intellisense (True, False) when I enter them into VB6. If I just type
in the boolean value and then run the program, I get an error. I even
tried to add a parameter to a function that already exists. In this
case, the intellisense showed the new parameter, but when I tried to
call it, I got an error about having the wrong number of parameters.

This sounds to me like I'm missing something when I re-deploy the DLL
to the VB6 machine. I tried re-registering the dll:

regasm c:\windows\system32\Test_Client.dll /unregister
regasm c:\windows\system32\Test_Client.dll

But it didn't seem to make any difference. I also tried to re-copy
the dll to the c:\windows\assembly folder, with no luck.

Also (and this also may be a symptom of the same problem), is there a
requirement that parameters must be ByRef??? I had some trouble with
that too...where a ByVal parameter (which was an array of strings)
didn't work, but a ByRef parameter did.

Please help me! I'm pulling my hair out!!! What am I missing?

7 Answers

Patrick Steele

2/22/2007 3:56:00 AM

0

In article <1172097422.418673.149420@s48g2000cws.googlegroups.com>,
drvice@nppd.com says...
> I'm having some issues I hope someone can assist me with.
>
> I have a VB6 application which needs to interact with a VB.NET
> assembly (dll). The VB6 application is being developed on a separate
> PC from my .NET development PC. I have setup the .NET assembly for
> COM interop and have given it a strong name (this is all done with VS
> 2005). I have also copied the DLL to the C:\windows\assembly folder on
> the VB6 PC which adds it to the GAC. When I create an instance of the
> dll in VB6:
>
> Global x as Test_Client.Client (this is actually in a Module)
> Set x = New Test_Client.Client
>
> and then access a function in the DLL:
>
> If x.TestFunction() = True then....
>
> It all seems to work pretty well. However, I'm seeing some wierd
> things when I update the .NET dll, rebuild it, and re-deploy it to the
> VB6 machine. Sometimes, my parameters don't show up in the VB6
> intellisense. Sometimes, my boolean functions won't give me the
> intellisense (True, False) when I enter them into VB6. If I just type
> in the boolean value and then run the program, I get an error. I even
> tried to add a parameter to a function that already exists. In this
> case, the intellisense showed the new parameter, but when I tried to
> call it, I got an error about having the wrong number of parameters.
>
> This sounds to me like I'm missing something when I re-deploy the DLL
> to the VB6 machine.

First off, copying a DLL to the C:\windows\assembly folder is not
"adding it to the GAC". To put something in the GAC you either need an
installer to do it or use the gacutil tool.

Second, is your .NET app developed in a way to make it "COM-friendly"?
In other words, have you defined GUIDs for all of your classes and
interfaces, defined proper DISP ids and do you maintain these same
values when you rebuild the .NET DLL?

--
Patrick Steele
http://weblogs.asp.n...

Dan Vice

2/22/2007 10:32:00 AM

0

On Feb 21, 9:56 pm, Patrick Steele <patr...@mvps.org> wrote:
> In article <1172097422.418673.149...@s48g2000cws.googlegroups.com>,
> drv...@nppd.com says...
>
>
>
>
>
> > I'm having some issues I hope someone can assist me with.
>
> > I have a VB6 application which needs to interact with a VB.NET
> > assembly (dll). The VB6 application is being developed on a separate
> > PC from my .NET development PC. I have setup the .NET assembly for
> > COM interop and have given it a strong name (this is all done with VS
> > 2005). I have also copied the DLL to the C:\windows\assembly folder on
> > the VB6 PC which adds it to the GAC. When I create an instance of the
> > dll in VB6:
>
> > Global x as Test_Client.Client (this is actually in a Module)
> > Set x = New Test_Client.Client
>
> > and then access a function in the DLL:
>
> > If x.TestFunction() = True then....
>
> > It all seems to work pretty well. However, I'm seeing some wierd
> > things when I update the .NET dll, rebuild it, and re-deploy it to the
> > VB6 machine. Sometimes, my parameters don't show up in the VB6
> > intellisense. Sometimes, my boolean functions won't give me the
> > intellisense (True, False) when I enter them into VB6. If I just type
> > in the boolean value and then run the program, I get an error. I even
> > tried to add a parameter to a function that already exists. In this
> > case, the intellisense showed the new parameter, but when I tried to
> > call it, I got an error about having the wrong number of parameters.
>
> > This sounds to me like I'm missing something when I re-deploy the DLL
> > to the VB6 machine.
>
> First off, copying a DLL to the C:\windows\assembly folder is not
> "adding it to the GAC". To put something in the GAC you either need an
> installer to do it or use the gacutil tool.
>
> Second, is your .NET app developed in a way to make it "COM-friendly"?
> In other words, have you defined GUIDs for all of your classes and
> interfaces, defined proper DISP ids and do you maintain these same
> values when you rebuild the .NET DLL?
>
> --
> Patrick Steelehttp://weblogs.asp.ne... Hide quoted text -
>
> - Show quoted text -

Patrick,

I'd read somewhere that installing to the GAC was that simple. I'll
use gacutil.

Second....yes, I believe I've got it all setup to be COM-friendly. I
used the following article on CodeProject as a template:

http://www.codeproject.com/dotnet/ne...

And I have got it to work...it's just when I make a change to the .NET
assembly and re-deploy it to the VB 6 PC that I see these wierd
issues.

Is re-deploying the dll and tlb files as easy as overwriting them? Or
do I need to do more? It's almost like I have some version issues or
something. Again, the best example of this adding a second parameter
to a function in the dll, re-deploying it and having the VB6
intellisense recognize the new parameter, but the VB6 runtime tells me
I'm using the wrong number of paramters.

Dan

TDC

2/22/2007 1:50:00 PM

0


> First off, copying a DLL to the C:\windows\assembly folder is not
> "adding it to the GAC". To put something in the GAC you either need an
> installer to do it or use the gacutil tool.


Actually, there is a provided explorer shell extension that will under-
the-covers invoke gacutil-like behavior when you drag-n-drop your
assembly onto the C:\windows\assembly folder.

As for the OP question, in COM you are not supposed to chnage
signatures without changing your GUIDs. And that will yield a new
TypeLib (which is what VB6 reads to give you intellisense). So make
sure you are registering your new typelibs on you VB6 machine.

Tom

Patrick Steele

2/22/2007 2:53:00 PM

0

In article <1172140293.033235.231150@m58g2000cwm.googlegroups.com>,
drvice@nppd.com says...
> And I have got it to work...it's just when I make a change to the .NET
> assembly and re-deploy it to the VB 6 PC that I see these wierd
> issues.
>
> Is re-deploying the dll and tlb files as easy as overwriting them? Or
> do I need to do more?

When you "make a change", are you adding any new methods, changing any
signatures/return types or anything? Or are you just changing the logic
of the code?

If you're just changing the logic, then yes, a simple overwrite should
suffice. But if you're adding new methods or changing existing methods,
you need to unregister your old DLL and re-register the new one.

The best thing to do is define the interfaces you'll need up-front and
set up all of the GUIDs, DispId's, etc... once. Then you just register
with regasm once and as you debug, you can simply copy the new file over
the old one.

--
Patrick Steele
http://weblogs.asp.n...

Dan Vice

2/22/2007 3:20:00 PM

0

On Feb 22, 8:53 am, Patrick Steele <patr...@mvps.org> wrote:
> In article <1172140293.033235.231...@m58g2000cwm.googlegroups.com>,
> drv...@nppd.com says...
>
> > And I have got it to work...it's just when I make a change to the .NET
> > assembly and re-deploy it to the VB 6 PC that I see these wierd
> > issues.
>
> > Is re-deploying the dll and tlb files as easy as overwriting them? Or
> > do I need to do more?
>
> When you "make a change", are you adding any new methods, changing any
> signatures/return types or anything? Or are you just changing the logic
> of the code?
>
> If you're just changing the logic, then yes, a simple overwrite should
> suffice. But if you're adding new methods or changing existing methods,
> you need to unregister your old DLL and re-register the new one.
>
> The best thing to do is define the interfaces you'll need up-front and
> set up all of the GUIDs, DispId's, etc... once. Then you just register
> with regasm once and as you debug, you can simply copy the new file over
> the old one.
>
> --
> Patrick Steelehttp://weblogs.asp.n...

TDC/Patrick,

Thanks for the information. Just so I'm clear...

1) If I'm changing signatures, then I need to use a new GUID for both
my interface and my class?
2) Also, If I'm changing signatures, I need to unregister and re-
register both the tlb and dll files. BTW: does regasm xxx.dll
register the tlb file too? Because, I am getting a new one from
VS2005 every time I build.

Dan

Dan Vice

2/23/2007 4:21:00 PM

0

On Feb 22, 9:20 am, drv...@nppd.com wrote:
> On Feb 22, 8:53 am, Patrick Steele <patr...@mvps.org> wrote:
>
>
>
>
>
> > In article <1172140293.033235.231...@m58g2000cwm.googlegroups.com>,
> > drv...@nppd.com says...
>
> > > And I have got it to work...it's just when I make a change to the .NET
> > > assembly and re-deploy it to the VB 6 PC that I see these wierd
> > > issues.
>
> > > Is re-deploying the dll and tlb files as easy as overwriting them? Or
> > > do I need to do more?
>
> > When you "make a change", are you adding any new methods, changing any
> > signatures/return types or anything? Or are you just changing the logic
> > of the code?
>
> > If you're just changing the logic, then yes, a simple overwrite should
> > suffice. But if you're adding new methods or changing existing methods,
> > you need to unregister your old DLL and re-register the new one.
>
> > The best thing to do is define the interfaces you'll need up-front and
> > set up all of the GUIDs, DispId's, etc... once. Then you just register
> > with regasm once and as you debug, you can simply copy the new file over
> > the old one.
>
> > --
> > Patrick Steelehttp://weblogs.asp.n...
>
> TDC/Patrick,
>
> Thanks for the information. Just so I'm clear...
>
> 1) If I'm changing signatures, then I need to use a new GUID for both
> my interface and my class?
> 2) Also, If I'm changing signatures, I need to unregister and re-
> register both the tlb and dll files. BTW: does regasm xxx.dll
> register the tlb file too? Because, I am getting a new one from
> VS2005 every time I build.
>
> Dan- Hide quoted text -
>
> - Show quoted text -

Just to complete this thread....this did work. Here are the steps I
used:

1) Gave my interface and my class new GUIDs.
2) Rebuilt the dll project from VS20005
3) Unregistered the assembly on the VB6 machine
4) Copied the dll and tlb files from the VS2005 machine to the VB6
machine
5) Registered the dll and tlb with the following command:
regasm c:\windows\system32\test_client.dll /tlb:c:\windows
\system32\test_client.tlb
6) Removed and re-added the dll to the GAC (I don't know if this was
necessary, but I did it anyway)

The methods then worked flawlessly in VB6. Thanks again for your
assistance!!

Dan

Patrick Steele

2/23/2007 11:14:00 PM

0

In article <1172247637.551639.113820@q2g2000cwa.googlegroups.com>,
drvice@nppd.com says...
> The methods then worked flawlessly in VB6. Thanks again for your
> assistance!!

Cool! Glag you got it working!

--
Patrick Steele
http://weblogs.asp.n...