Hook (Sending Message from a Visual C++ App To a Visual Basic App) 
Author Message
 Hook (Sending Message from a Visual C++ App To a Visual Basic App)

I have a small application in Visual C++ that send a BroadCast message to all top-window. Here is the Code. (Blue highlights are the important lines)

MASTER

BOOL CIpcMasterDlg::OnInitDialog(){
s_uWatchDogMsg = RegisterWindowMessage("ProxyWatchDog") ;

Quote:
}

BOOL PostBroadcastIpcMessage(WPARAM wParam, LPARAM lParam)
{ BOOL bRes;

  bRes = PostMessage(
   HWND_BROADCAST,
   s_uWatchDogMsg,       // message
   wParam,  // first message parameter
   lParam   // second message parameter
  );
 return(bRes) ;

Quote:
}

The Code used to received the message in a Visual C++ App are:

SLAVE

BOOL CIpcSlaveDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 // Add "About..." menu item to system menu.

 // IDM_ABOUTBOX must be in the system command range.
 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
 ASSERT(IDM_ABOUTBOX < 0xF000);

 CMenu* pSysMenu = GetSystemMenu(FALSE);
 if (pSysMenu != NULL)
 {
  CString strAboutMenu;
  strAboutMenu.LoadString(IDS_ABOUTBOX);
  if (!strAboutMenu.IsEmpty())
  {
   pSysMenu->AppendMenu(MF_SEPARATOR);
   pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  }
 }

 // Set the icon for this dialog.  The framework does this automatically
 //  when the application's main window is not a dialog
 SetIcon(m_hIcon, TRUE);   // Set big icon
 SetIcon(m_hIcon, FALSE);  // Set small icon

 // TODO: Add extra initialization here
 s_uWatchDogMsg = RegisterWindowMessage("ProxyWatchDog") ;
 m_csWdMsg = "" ;

 return TRUE;  // return TRUE  unless you set the focus to a control

Quote:
}

LRESULT CIpcSlaveDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
 // TODO: Add your specialized code here and/or call the base class
 if(message == s_uWatchDogMsg) {
  m_csWdMsg.Format("WPARAM: %d", wParam) ;
 UpdateData(FALSE) ;

 }
 return CDialog::WindowProc(message, wParam, lParam);

Quote:
}

SLAVE IN Visual Basic 6.0

Now, i'm trying to make the SLAVE application in Visual Basic, and i tried to do the following:

Private Sub Form_Load()
        GlobalMess = RegisterWindowMessage("ProxyWatchDog") 'API Function
             gHW = Me.hwnd
             Hook
End Sub

Public Sub Hook()
            lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
             AddressOf WindowProc)
             Debug.Print lpPrevWndProc
End Sub

Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _
   ByVal wParam As Long, ByVal lParam As Long) As Long
   Debug.Print uMsg
   If uMsg = GlobalMess Then
       MsgBox "Message Received !!"
   End If
    WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, _
       lParam)
End Function

But nothing happens. The WindowProc is not generate when i sent a brodcast message from the MASTER Application. What i'm doing wrong ?

Thank You..

Mauricio



Tue, 04 Nov 2003 22:44:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Help with Visual Basic ActiveX DLL showing form within Visual C++ app

2. Help with Visual Basic ActiveX DLL showing form within Visual C++ ATL app

3. HTLP - Sending messages from C++ to Visual Basic

4. HTLP - Sending messages from C++ to Visual Basic

5. Opening Lotus Notes App from Visual Basic App?

6. Visual C++ and Visual Basic and Visual J++

7. need some basic information on visual basic and visual c++

8. need some basic information on visual basic and visual c++

9. Visual C++ vs Visual Basic

10. Visual C++/Visual Basic/COM problem

11. visual basic vs. visual c++ which is better

12. Visual BASIC or Visual C++

 

 
Powered by phpBB® Forum Software