Is there a way to send messages from C#.NET assembly(ActiveX) to VB6 application?

浪子不回头ぞ 提交于 2019-12-06 08:23:45

The sample code to achieve this can be programmed using WM_COPYDATA and SENDMESSAGE.

From the .NET app you can send a message. On VB6 side you will have to create a message hook. This hook will loop using the WNDPROC function and catch messages sent to it.

Refer foll. 2 links with sample code:-

For C#.NET: C# Windows app uses WM_COPYDATA for IPC (CSSendWM_COPYDATA)

For VB6: How To Pass String Data Between Applications Using SendMessage

Both above can be combined in such way that you can pass data between C#.NET and VB6 applciaiton...

A quick and dirty way:

  1. When the exe runs have it store the hwnd of a textbox in the registry (or use FindWindow from the dll)
  2. Have the dll read the hwnd and use SendMessage + WM_SETTEXT to set its text
  3. This will raise the textbox change event in the VB6 exe which can then simply read its .text

WM_COPYDATA message. Take a look at this question

The basic idea is :

1 - In your activex dll initialize a buffer with the required data to send

2 - Your activex dll finds (FindWindow) the target application window

3 - Your activex dll sends a WM_COPYDATA message to the target window with a pointer to the buffer.

4 - Your vb6 application receives the message and reads the sended data.

OS handles the necessary conversion in address spaces between the two processes, but you will need to subclass the receiving window in your application to be able to receive the message.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!