开发者

2 running programs vb6 and c# - transfer a simple string between them

开发者 https://www.devze.com 2022-12-08 18:14 出处:网络
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, j

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


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!


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.)


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.


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


If the VB6 program is already running, you could use an out-of-process COM object (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.

0

精彩评论

暂无评论...
验证码 换一张
取 消