tags:

views:

381

answers:

6

Is there a good simple way to do this... it's just a simple string in c# i'd like to get over to an older vb6 app that will be rewritten later, don't need an extensive framework, just a quick and dirty, but reliable way to do this-- thanks!

also, I can modify the vb6 code

A: 

A socket or COM.

Taylor Leese
might be alot of effort for just 1 string i need to do, any other ways?,
Scott Kramer
+1  A: 

Depending on what components you have, you can broadcast a message from c# that the vb app can receive.

On the C# side you need to do something similar to a VirtualAlloc (hMem), upload the string data in that memory, use RegisterWindowMessage (idMsg) to get a unique WM_ message, SendMessage(HWND_BROADCAST, idMsg, hMem, 0);, the clean up after yourself with VirtualFree.

On the VB side, you'd need to subclass your window (you can get .ocx controls for this, google around a bit) and after you register the same message, listen to it. Once you receive it you get a pointer to your string. At this point you can either use rtl functions to retrieve the data from the pointer or just pass it to a com object and have it return a com string that you can use natively in VB.

Hope this helps!

Blindy
cool, I do some things like that in c#, like grab usb messages, but i bet its horrific in vb6, or just more than I want to learn about in vb6
Scott Kramer
i might end up just dropping a txt file, don't like it, but would work and is easy
Scott Kramer
i was hoping for a secret 1 liner, that could talk to each other
Scott Kramer
There aren't any secret 1 liners, inter process communication is a touchy subject. You need a medium and a synchronization flag for it to work. Sockets and window messages cover both of those. Shared memory (and files) only cover the medium, you need to implement the synchronization yourself (how do I know I should start reading? How do I know the writer is done writing?). I think my way is pretty solid, even though it has little to no framework support on the vb side.
Blindy
it is absolutly solid, im just not willing to do the vb6 side
Scott Kramer
+1  A: 

You can use DDE, which is specifically meant for communicating between apps in VB6. It can be used in .Net, but DDE is an older communication method and not really well supported in .Net.

I've done it using NDdE, but even that is no longer maintained or supported.

However, if you're willing to look into it, here's a link to download it: http://ndde.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=4828

It works pretty well, but given the lack of support, it is probably not your best option.

Since it looks like you're looking for something really simple and you don't care that it's a hack, you could always just post messages to a shared database, or write files to a pre-determined location and have the two apps look there. Web services are an option, but I doubt there is much support in VB6. (It's been years since I worked with VB6, so I don't know what kinds of 3rd party options are available for this.)

David Stratton
thanks for the ideas!, yep i'm thinking about dropping a shared file
Scott Kramer
A: 

If the VB6 program is already running, you could use an ActiveX exe as a middleman? Something like this answer of mine about communicating between MatLab and VB.
If you are launching the VB6 program from the C# program, just make the VB6 program itself an ActiveX exe. Or just pass the string on the command line.

MarkJ
A: 

The best way to do it is through ROT (Running Objects Table). Here is a sample.

You register an object in ROT and make it discoverable by other application. The sample registers a C# object and in VB6 just does a GetObject(, "ROTProviderDotNetDlg.COMROTVictim") to access it. Then you can call methods, set properties, etc.

Same can be done the other way around -- a VB6 object can be registered in ROT, then accessed by the C# app to call methods on the VB6 object.

wqw
A: 

setup a textbox on vb6, the events on the textbox are raised by sendcomand on the textbox window , just catch the events you need to find the correct value for each event, I used the doubleclick

Arabcoder