Solved

MessageBox Api Hook

Posted on 2003-11-16
3
5,028 Views
Last Modified: 2011-10-03
I need some vb code for a program that will set up a system api hook for the MessageBox function.  When an external program calls the MessageBox function, my program, which is running, needs to be able to find out the text that the messagebox reported.

Thanks,

vbwizardxxx
0
Comment
Question by:vbwizardxxx
3 Comments
 
LVL 3

Accepted Solution

by:
NBrownoh earned 250 total points
ID: 9761401
'put in declarations part of a form
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long


Private Sub Form_Load()
    Dim x As Long, staticx As Long, MyStr As String
    x = FindWindow("#32770", vbNullString)
    staticx = FindWindowEx(x, 0&, "static", vbNullString)
    MyStr = String(100, Chr$(0))
    GetWindowText staticx, MyStr, 100
    MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
    MsgBox MyStr
End Sub

'--

this will msgbox you the text contained in the first message box found, to test it open up another instance of VB and in the form_load proc just put msgbox "Hey there"

then run this program, it will display a message box of the text it grabbed from the other message box.
0
 

Expert Comment

by:validtec
ID: 10234036
Try out API Hook SDK
http://www.validtec.com
Windows API Hook SDK that can hooking most API of Windows System or functions in 3rd Application's DLL
0
 

Expert Comment

by:mksipila
ID: 13837761
I tried to implement what you have above, but my variable keeps coming back empty from the Original Message Box. Am I missing something?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now