Solved

MessageBox Api Hook

Posted on 2003-11-16
3
5,033 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now