PC Review


Reply
Thread Tools Rate Thread

Coomunicatioin between .Net and VB6 Apps

 
 
Martin Horner
Guest
Posts: n/a
 
      8th Dec 2003
Hi,

I have an existing VB6 application that I intend to add some additional
functionality to. This app will be eventually converted to .NET but probably
not in the near future. The new functionality will not have a really close
dependency on the exiting application other than sharing a common database.
One option that I have been considering is to build the new functionality
into a VB.Net application. It is likely that I will use a standard EXE or an
ActiveX.Exe in VB6 because the existing application is MDI and I also need a
new MDI window for the new functionality.

So here is my question. I am looking for a simple way to establish two way
communications between the two applications. I would like to avoid using the
SendMessage function if possible so that the communications has room to
grow. In the first instance this is what I would like to do:
1. Start the .NET application from the VB6 or activate it if it is running.
2. Provide it with some start up data.
3. Optionally hide or leave the VB6 application running when the .Net
application is running.
3. Activate or close the VB6 application when the .Net application closes

Ideally I would also like to raise events (or otherwise send messages) from
the .Net application to the VB6 application. Can anyone point me in the
right direction on the best tools I can use to implement this? In VB6 I
would almost certainly implement the new application as an ActiveX server.
So I guess I am looking for a replacement for this in a combined COM and
..Net world.

Thanks.


 
Reply With Quote
 
 
 
 
smith
Guest
Posts: n/a
 
      8th Dec 2003
This is what Interop is all about.

Make your new VB.Net app and give it events you want ot expose to the VB6
app, add COM GUIDs, compile and build a type library.

declare the tlb in your vb6 app WithEvents and you can code against those
events (and all of the Public objects and interfaces) ... there's your
communication.

Pick up the Lhotka & Hollis book on Iterop:

http://www.amazon.com/exec/obidos/tg...books&n=507846

It was on WROX but you should still be able to find it at bigger bookstores.

You'll find it all falls into place very simply ... wait till you get into
using autodeploy on those vb7 applets you're calling from VB6! (And then
when you make all of those autodeployed applets use remoting!) That's when
this stuff gets fun to code

-smith
kirkland, wa


 
Reply With Quote
 
Martin Horner
Guest
Posts: n/a
 
      9th Dec 2003
That is very good information. One of the reasons I was looking at an
ActiveX.Exe in VB6 is that it allowed both the old and the new application
to use an MDI. When I put together a quick pair of test applications I found
that both the client VB6 and the server .Net application could show MDI
windows. This is great if there are no adverse side effects (and the only
reason that I think there might be is because you can't add one to a VB6
dll.

In my test I couldn't declare the .Net component WithEvents but I guess the
technique for doing this must be included in Professional Visual Basic
Interopability that you recommended and that I will get hold of

Thanks again.

"smith" <(E-Mail Removed)> wrote in message
newssXAb.5430$(E-Mail Removed)...
> This is what Interop is all about.
>
> Make your new VB.Net app and give it events you want ot expose to the VB6
> app, add COM GUIDs, compile and build a type library.
>
> declare the tlb in your vb6 app WithEvents and you can code against those
> events (and all of the Public objects and interfaces) ... there's your
> communication.
>
> Pick up the Lhotka & Hollis book on Iterop:
>
>

http://www.amazon.com/exec/obidos/tg...books&n=507846
>
> It was on WROX but you should still be able to find it at bigger

bookstores.
>
> You'll find it all falls into place very simply ... wait till you get into
> using autodeploy on those vb7 applets you're calling from VB6! (And then
> when you make all of those autodeployed applets use remoting!) That's

when
> this stuff gets fun to code
>
> -smith
> kirkland, wa
>
>



 
Reply With Quote
 
Peter Huang
Guest
Posts: n/a
 
      9th Dec 2003
Hi Martin,

Here I write a sample about how to expose the event of .NET component to
VB6.
[TestComObject.Class1]
Imports System.Runtime.InteropServices
Public Delegate Sub testdelegate()
<GuidAttribute("1F98211C-7A71-4588-8D4A-AD85CA80BAE7"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface ControlEvents
<DispIdAttribute(1)> _
Sub testevent()
End Interface
<ComSourceInterfaces(GetType(ControlEvents)),
ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class Class1
Dim WithEvents fm As Form1
Public Sub test()
fm = New Form1
fm.Show()
End Sub
Public Event testevent()
Private Sub fm_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fm.Closed
RaiseEvent testevent()
End Sub
End Class


[VB6 code]
Dim WithEvents o As TestComObject.Class1
Private Sub Command1_Click()
Set o = New TestComObject.Class1
o.test
End Sub
Private Sub o_testevent()
MsgBox "event fired"
End Sub

HOW TO: Sink Managed Visual Basic .NET Events in Internet Explorer Script
http://support.microsoft.com/?kbid=316516

Exposing .NET Framework Components to COM
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconexposingnetframeworkcomponentstocom.asp

If you have any concern please post here.

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.

 
Reply With Quote
 
Martin Horner
Guest
Posts: n/a
 
      9th Dec 2003
Hi Peter,

That sample is great and the links are very useful too. This gives me the
foundation to perform all the processing I will need to do in the first
instance. I thought I would need to wait until I got some more reference
material but I now have everything I need to get going. Thanks

Martin


"Peter Huang" <v-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Martin,
>
> Here I write a sample about how to expose the event of .NET component to
> VB6.
> [TestComObject.Class1]
> Imports System.Runtime.InteropServices
> Public Delegate Sub testdelegate()
> <GuidAttribute("1F98211C-7A71-4588-8D4A-AD85CA80BAE7"), _
> InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
> Public Interface ControlEvents
> <DispIdAttribute(1)> _
> Sub testevent()
> End Interface
> <ComSourceInterfaces(GetType(ControlEvents)),
> ClassInterface(ClassInterfaceType.AutoDual)> _
> Public Class Class1
> Dim WithEvents fm As Form1
> Public Sub test()
> fm = New Form1
> fm.Show()
> End Sub
> Public Event testevent()
> Private Sub fm_Closed(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles fm.Closed
> RaiseEvent testevent()
> End Sub
> End Class
>
>
> [VB6 code]
> Dim WithEvents o As TestComObject.Class1
> Private Sub Command1_Click()
> Set o = New TestComObject.Class1
> o.test
> End Sub
> Private Sub o_testevent()
> MsgBox "event fired"
> End Sub
>
> HOW TO: Sink Managed Visual Basic .NET Events in Internet Explorer Script
> http://support.microsoft.com/?kbid=316516
>
> Exposing .NET Framework Components to COM
>

http://msdn.microsoft.com/library/de...us/cpguide/htm
> l/cpconexposingnetframeworkcomponentstocom.asp
>
> If you have any concern please post here.
>
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help - Alt-E hotkey does not work in MSOffice apps, no prob in other apps Bob Newheart Microsoft Excel Misc 3 28th Jul 2008 02:24 AM
backup apps -> reinstall xp -> restore apps? km@mathcs.emory.edu Windows XP General 5 6th May 2007 05:11 PM
config files question for console apps / windows apps jai hanuman Microsoft Dot NET Framework Forms 2 15th Mar 2004 08:44 AM
winsock problem? some apps can't access any web site, most apps have no problems. W2K SP4+ Clark Wilson Microsoft Windows 2000 Networking 1 14th Sep 2003 02:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:59 AM.