Results 1 to 25 of 25

Thread: [RESOLVED] [2008] Error boxes killing me

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Resolved [RESOLVED] [2008] Error boxes killing me

    First off, this is not something I coded but rather a product I had created for me. In any case I have no source to edit just a buggy program that I'd like to destroy now. When I run the application it runs fine for a bit and then starts throwing error messages then if you click on no I don't want to debug it will continue as normal and then throw more boxes until it is finished.

    What I want to create is a little program that will watch for those boxes and automatically click the no box for me behind the scenes so I can continue working on things.

    What can I use to watch for those boxes and then kill them?

    Chris

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2008] Error boxes killing me

    Are you familiar with Spy++? I would suggest using that to see if you can reliably identify the boxes and the buttons on the box. If so, then you can use API calls to check for the existence of them. You'd probably want to do the check in a fairly fast timer, but the check shouldn't be very slow, so you could probably set the timer interval to 200 and be fine. That would mean that the worst wait would be one fifth of a second, which isn't much.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    I've heard of it but never used it before. I know the titles of the boxes and figured there was a listener class that I could code to listen for the boxes to be called and kill them that way but I've been searching for sample code to use and been unsuccessful so far.

    Do you know what api to use for that? is it WinAPI MessageBox?

    Chris

  4. #4
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [2008] Error boxes killing me

    Decompile it and you'll have a 1:1 source.
    VB 2005, Win Xp Pro sp2

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    Decompile it? Oh boy...wouldn't it be easier to code a simple listener to kill the boxes?

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2008] Error boxes killing me

    What's it written in? If it was written in .NET, then decompiling might be a reasonable way to go.

    Spy++ comes with Visual Studio, so you probably have it. It's a neat little tool to play around with, even if you don't end up using it. There are probably many more pieces than I have used, but the two critical ones that I can see for you are the crosshairs tool, and the form that shows all windows on the screen. You might be surprised at the number of windows displayed unless you realize that EVERYTHING is a window. Every button, icon, taskbar, etc. You would want to bring that up when the box in question is on the screen, then try to find it in the list of windows. Next you'd press the button and wait for the next box and find it in the list, and so on. What you'd be looking for is some common identifying characteristic. They might all be the same windows class, or they might all be children of some other form, or they might all have readily identifiable captions (you wouldn't really need Spy++ to see that).

    The crosshairs tool can be used by moving it around on the screen. When you move it over any window (and everythings a window) it shows you various information about the window, such as class, and so forth.

    This is the first step that I would take, and it may not work. It is possible that you simply won't notice any pattern to the boxes that you can latch onto. For the API calls I am thinking of, you'd need to be able to get the handle for the window that you want to send the message to, and you can get the handle via the caption, or via the windows class, but some windows have no captions, and the windows class for a messagebox is certainly not going to be unique. Therefore, if there is no caption, then you need to be able to say, "I want the second instance of windows class C located below window W." If you can find a pattern like that, the rest is not so difficult.

    Perhaps others will have an easier way, though, since this is a messagebox.
    My usual boring signature: Nothing

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Error boxes killing me

    writing a program to click msgboxes that way is a hack.
    i'd decompile the original program + rewrite it

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    Thanks Shaggy Hiker. It is a .net app. Where can I find Spy++?

    Chris

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Error boxes killing me

    Spy++ is included with the pro edition of vs2005, so i'd assume also vs2008 pro. doesn't appear to come with vb2008 express though.
    if you have got it it'll be in your Visual Studio Tools menu

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    Damn...it's not. Ok...I am pretty frustrated with it, I would decompile it if I knew how to, I found Red Gate's .net reflector but I don't know if that is possible to use. There is a lot of functions in here.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    I've got it fully decompiled now but it has a lot of errors now in the code that I don't think I can fix. I used .net reflector and one of their add ins to decompile it back to vb.net but it's not all good code. what can I do?

    Here is example decompiled code with error:

    vb Code:
    1. Private Sub button_sort_Click(ByVal sender As Object, ByVal e As EventArgs)
    2.             Dim control As Control
    3.             For Each control In Me.tabControl1.SelectedTab.Controls
    4.                 control.Enabled = False
    5.             Next
    6.             Dim list As New List(Of Uri)
    7.             Dim str As String
    8.             For Each str In Me.textBox_result.Text.Split(Me.newline, 0)
    9.                 Try
    10.                     Dim uri As New Uri(str.Trim)
    11.                     list.Add(uri)
    12.                 Catch obj1 As Object
    13.                 End Try
    14.             Next
    15.             If (Form1.CS$<>9__CachedAnonymousMethodDelegate4 Is Nothing) Then
    16.                 Form1.CS$<>9__CachedAnonymousMethodDelegate4 = New Comparison(Of Uri)(Nothing, Form1.<button_sort_Click>b__3)
    17.             End If
    18.             list.Sort(Form1.CS$<>9__CachedAnonymousMethodDelegate4)
    19.             Me.textBox_result.Text = ""
    20.             Dim uri As Uri
    21.             For Each uri In list
    22.                 Me.textBox_result.AppendText((uri.ToString & ChrW(13) & ChrW(10)))
    23.             Next
    24.             Dim control As Control
    25.             For Each control In Me.tabControl1.SelectedTab.Controls
    26.                 control.Enabled = True
    27.             Next
    28.         End Sub

    Here is the error:
    vb Code:
    1. If (Form1.CS$<>9__CachedAnonymousMethodDelegate4 Is Nothing) Then
    2.                 Form1.CS$<>9__CachedAnonymousMethodDelegate4 = New Comparison(Of Uri)(Nothing, Form1.<button_sort_Click>b__3)
    3.             End If
    4.             list.Sort(Form1.CS$<>9__CachedAnonymousMethodDelegate4)

    ideas?
    Last edited by cmmorris1; Oct 23rd, 2008 at 07:54 PM.

  12. #12
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [2008] Error boxes killing me

    Well then back to Shaggy's idea. If you don't have Spy++, use WinID. It is perfect for investigating different types of windows.
    VB 2005, Win Xp Pro sp2

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    I found spy++ for vs 2008 finally although not in the tools menu. Did some looking with the crosshairs and there is a message box with Error in the title of the form that has two buttons to click. I just need to know what code to use to look for error message box and click no.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    I fixed a lot of the code errors in the project but when I run the application it starts up fine and I enter my license code for the program and then it breaks and shows me this in the debugger:

    Nevermind...I fixed that...crosses fingers.
    Last edited by cmmorris1; Oct 23rd, 2008 at 09:53 PM.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    Still too many errors here...does anyone know how to create a simple program to watch for error boxes and click no?

    chris

  16. #16
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [2008] Error boxes killing me

    Here is one way to click the 'No' button in Notepad when it asks you on close if you want to save the changes.

    Start notepad, type something and try to close it. A dialog will pop and ask you "Do you want to save the changes?" Leave it open and run the code bellow. In your case, you must change the strings in the FindWindow and FindWindowEx accordingly (see what Spy++ is telling you).
    Code:
        'api constant declarations
        Const BM_CLICK As Integer = &HF5
    
    
        'sendmessage overload that is used to send messages to the button 
        Private Declare Auto Function SendMessage Lib "user32.dll" Alias "SendMessage" _
        (ByVal hWnd As IntPtr, ByVal Msg As Integer, _
        ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr
    
    
        'API to find the dialog window
        Private Declare Auto Function FindWindow Lib "user32" _
        (ByVal ClassName As String, ByVal WindowTitle As String) As IntPtr
    
        'API to find some sub window inside the dialog window
        Private Declare Auto Function FindWindowEx Lib "user32" _
        (ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, _
        ByVal ClassName As String, ByVal WindowTitle As String) As IntPtr
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
    
    
            Dim ParentWindowHWND As IntPtr
            Dim ChildWindowHWND As IntPtr
    
    
            'as seen with Spy++, the class name of the Dialog is #32770, the text is "Notepad"
            'search for the handle of the dialog
            ParentWindowHWND = FindWindow("#32770", "Notepad")
    
    
            'now you'll have to find the "No" buton. Spy++ will show you that the class name of the button
            'is "Button" and the text is "No". The latter is false, it actually has
            'an accelerator (underscore below N). WinID is not making the same mistake.
            'Anywayz, add '&' appropriately.
            If ParentWindowHWND <> IntPtr.Zero Then
                ChildWindowHWND = FindWindowEx(ParentWindowHWND, IntPtr.Zero, "Button", "&No")
            Else
                MessageBox.Show("Program is not running.", "Error")
            End If
    
            'we have the handle of the No button, so let's click it
            SendMessage(ChildWindowHWND, BM_CLICK, 0, IntPtr.Zero)
    
        End Sub
    VB 2005, Win Xp Pro sp2

  17. #17
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [2008] Error boxes killing me

    was the program actually written 2008? If it was written in 2005 that may be the source of some of the errors. And are you getting actual errors or are they "warning"s? Would love to see a screenshot or something of the error list.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    It was written in 2005 and I converted to 2008 Lord Orwell.
    There is about 100 Actual errors in the code that make no
    sense to me.

    One of those is in this line here:

    If (Form1.CS$<>9__CachedAnonymousMethodDelegate4 Is Nothing) Then

    I have no idea what that even means?

    Chris

  19. #19
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Error boxes killing me

    a little late to the party...

    if it is something you had created, and it isn't working, why use it?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    Well it was created for me, it works as far as what it does but I can't fix the error boxes that keep popping up on me. I've got the source to it now but I spent 3 hours last night trying to fix it myself and it's killing me

    If I could fix it then I'd be happy, if not then a fix like creating a listener to kill the error boxes wouldn't be so bad.

  21. #21
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2008] Error boxes killing me

    I would say that fixing the errors is superior to the button clicker, but the source you have comes from decompiling, right? That would mean that some of the names could be looking a bit odd, such as the one you posted.

    The line in question is looking to see whether something is nothing. You know it is associated with Form1, but it is not Form1 itself. It doesn't really look like a member variable, so I would take a look at the properties of form1, and look at the code around it to see whether there is a property that would make sense in that context.

    For the button clicker, Hack's code would be the place to start, especially with all the comments.
    My usual boring signature: Nothing

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    I did spend a lot of time last night attempting to do just that, I also thought about hiring someone to do the same software again but only if I had to go that route. I'm fairly new to this so coding the entire thing isn't an option but I'm definitely learning a lot as I go so this is good in that respect. I will keep plugging away at that and see if I can't repair it myself.

  23. #23
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Error boxes killing me

    if you don't mind me asking, what does this code do?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Error boxes killing me

    No..not at all, this is a little web scraper utility that I use for my niche businesses.

  25. #25
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [2008] Error boxes killing me

    is ... that ... ALL?!? exactly how many lines approximately are you dealing with? There are a bunch of sample scraper codes on this forum already. Perhaps someone could help you rewrite something from scratch without errors in it. Actually, uploading the code would help as well.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width