Solved

MessageBox Api Hook

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

776 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