Option Explicit
Private Const WM_COPYDATA As Long = &H4A 'An application sends the WM_COPYDATA message to pass data to another application.
Private Type COPYDATASTRUCT 'Contains data to be passed to another application by the WM_COPYDATA message.
dwData As Long ' The data to be passed to the receiving application.
cbData As Long ' The size, in bytes, of the data pointed to by the lpData member.
lpData As Long ' The data to be passed to the receiving application. This member can be NULL.
End Type 'http://msdn.microsoft.com/en-us/library/ms649010(v=vs.85).aspx
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Declare Function SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Public Sub SendData(ByRef frmSender As Form, ByVal OtherApphWnd As Long, ByRef strMsg As String)
Dim CDS As COPYDATASTRUCT
CDS.dwData = frmSender.hWnd 'WM_COPYDATA needs to know who sent
CDS.cbData = LenB(strMsg) + 2& 'Include room for null terminator so SysReAllocString
CDS.lpData = StrPtr(strMsg) 'can determine the string's length
'SendMessage won't return until the data has been sent and the recipient has responded.
SendMessage OtherApphWnd, WM_COPYDATA, CDS.dwData, CDS
End Sub