VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 793|回复: 8

求高人指点程序间通讯

[复制链接]

1

主题

6

帖子

7.00

积分

新手上路

Rank: 1

积分
7.00
发表于 2020-1-7 21:40:01 | 显示全部楼层 |阅读模式
有两个程序A,B,一个ActiveX DLL文件中C定义Report方法,A,B同时引用,A为主动方,B为被动方,现在想A通过C Report一条消息给B,B在收到后开始处理此消息,现在问题是B无法触发C的Report方法,请高人帮忙指点一下,谢谢!
C。
Public Function OnReport(rptStr As String) As String
End Function

A.
Set sendcls = New itfClass
sendcls.report “Hello”

B.
Private  Function itfClass_OnReport(rptStr As String) As String  
MsgBox rptStr
End Function
回复

使用道具 举报

1

主题

6

帖子

7.00

积分

新手上路

Rank: 1

积分
7.00
 楼主| 发表于 2020-1-9 19:18:01 | 显示全部楼层
简单说就是:
A发生变化时要通知B知道,通过双方共同引用的DLL实现,谢谢!
回复

使用道具 举报

1

主题

6

帖子

7.00

积分

新手上路

Rank: 1

积分
7.00
 楼主| 发表于 2020-1-19 09:54:01 | 显示全部楼层
看到有人说要用activeX exe实现,一定得是这样做吗??
回复

使用道具 举报

1

主题

21

帖子

21.00

积分

新手上路

Rank: 1

积分
21.00
发表于 2020-1-19 13:18:01 | 显示全部楼层
帮你顶,我来学习
回复

使用道具 举报

0

主题

8

帖子

7.00

积分

新手上路

Rank: 1

积分
7.00
发表于 2020-1-25 09:27:01 | 显示全部楼层
'利用WM_COPYDATA 发消息

'程序1
Private Const WM_COPYDATA = &H4A
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Type COPYDATASTRUCT
        dwData As Long
        cbData As Long
        lpData As Long
End Type

Private Sub Command1_Click()
  Dim cd As COPYDATASTRUCT
  Dim temp As String
  Dim Data() As Byte
  Dim m As Long
  
    m = FindWindow("ThunderRT6FormDC", "CopyData Test Form!")
  
    temp = "This is a Test Message!"
    Data = temp
    cd.cbData = UBound(Data) + 1
    cd.lpData = VarPtr(Data(0))
    cd.dwData = 0
  
    SendMessage m, WM_COPYDATA, 0, cd
End Sub








'程序2
'窗体
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const SPI_GETWORKAREA        As Long = 48
   
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Sub Form_Load()
  Dim ret As Long
  prevWndProc = GetWindowLong(Me.hWnd, GWL_WNDPROC)
  ret = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf Windproc)
  Me.Caption = "CopyData Test Form!"
  Me.AutoRedraw = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Dim ret As Long
  ret = SetWindowLong(Me.hWnd, GWL_WNDPROC, prevWndProc)
End Sub








'模块
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

  Public Const WM_COPYDATA = &H4A
  Public Const GWL_WNDPROC = (-4)
Public prevWndProc As Long

Private Type COPYDATASTRUCT
        dwData As Long
        cbData As Long
        lpData As Long
End Type


Function Windproc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   Dim Cd As COPYDATASTRUCT
   Dim Temp As String
   
   Select Case Msg
     Case WM_COPYDATA
      
       CopyMemory Cd, ByVal lParam, Len(Cd)
       Temp = Space(Cd.cbData)
       CopyMemory ByVal Temp, ByVal Cd.lpData, Cd.cbData
       Form1.Print StrConv(Temp, vbFromUnicode)

   End Select
   
    Windproc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
End Function
回复

使用道具 举报

0

主题

6

帖子

4.00

积分

新手上路

Rank: 1

积分
4.00
发表于 2020-1-28 19:27:01 | 显示全部楼层
dde 也可以实现 而且比较简单 你google 一下
不过。net开始不支持dde了
回复

使用道具 举报

1

主题

6

帖子

7.00

积分

新手上路

Rank: 1

积分
7.00
 楼主| 发表于 2020-2-1 11:09:01 | 显示全部楼层
谢谢各位的回答。我有看到过用DLL实现的程式,但当我自己来做的时候发现事件不响应啊??
回复

使用道具 举报

1

主题

6

帖子

7.00

积分

新手上路

Rank: 1

积分
7.00
 楼主| 发表于 2020-7-16 20:30:01 | 显示全部楼层
不知道通过DLL怎么实现,请高手继续指点啊。
回复

使用道具 举报

1

主题

6

帖子

7.00

积分

新手上路

Rank: 1

积分
7.00
 楼主| 发表于 2020-7-21 15:30:01 | 显示全部楼层
高手快来啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表