Results 1 to 19 of 19

Thread: [RESOLVED] Why doesn't this work when compiled?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] Why doesn't this work when compiled?

    Code:
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Option Explicit
    Private Const PROCESS_QUERY_INFORMATION = &H400
    Private Const STATUS_PENDING = &H103&
    
    Private Sub CmdPingPong_Click()
    
    'On Error Resume Next
    
    Dim sPath As String
    
    sPath = "c:\ping pong.exe"
    
    Me.Hide 'Hide the form so it won't confuse the user
    
    DoEvents
    
    MsgBox "Extracting program"
    
    ExtractEXE sPath
    
    DoEvents
    
    RunShell sPath
    
    DoEvents
    
    MsgBox "The program closed... deleting"
    
    Kill sPath
    
    DoEvents
    
    Me.show 'Bring the form back up when the game has closed.
    
    End Sub
    
    Private Sub ExtractEXE(Path_ As String)
    
    On Error Resume Next
    
    Dim strPath As String, intFF As Integer
    Dim bytData() As Byte
    
    strPath = Path_
    
    intFF = FreeFile
    bytData() = LoadResData(101, "CUSTOM")
    
    Open strPath For Binary Access Write As #intFF
    
    Put #intFF, , bytData()
    
    Close #intFF
    
    Erase bytData()
    
    End Sub
    
    Private Sub RunShell(cmdline As String)
    
    Dim hProcess As Long
    Dim ProcessId As Long
    Dim exitCode As Long
    
    ProcessId = Shell(cmdline, 1)
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
    
    Do
    
    Call GetExitCodeProcess(hProcess, exitCode)
    DoEvents
       
    Loop While exitCode = STATUS_PENDING
    
    Call CloseHandle(hProcess)
    
    End Sub

    In the VB6 IDE, this runs perfectly... but when i compile it, it gives me "Invalid Procedure call or argument" error, or sometimes it just says "The program closed... deleting" and executes it for like half a second (I don't know how that happens). The exe is a ping pong game that's a resource. Extracted by itself it works fine (As it was made in DarkBasic).

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why doesn't this work when compiled?

    You might want to remove the resume next error statement and add regular error handling so you can get the real error message to trak down the issue. resume next just supresses the error messages.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    Quote Originally Posted by RobDog888
    You might want to remove the resume next error statement and add regular error handling so you can get the real error message to trak down the issue. resume next just supresses the error messages.

    But it works fine, with no errors when in the VB IDE.

    It only errors when it's compiled.

    I'll do what you said and post it here.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    I can't get it to replicate the "Invalid Procedure call" error. Now all's it does is execute the game, and then close it.

    I commented out all the "On Error Resume Next" lines.

    It still works fine in the VB IDE however, it only errors when it's compiled.

    Maybe there's another way to execute it and wait to see when it's closed?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    Also does this on a friends computer.

    Though he don't have VB installed, so i can't check if it runs fine when inside the IDE.

    Do you know what's causing this error?

    I think it's the bit that checks if a process is open or not inside the RunShell function.
    Do you know another API or something i could use to detect if the program that was executed was closed or not?
    Last edited by Slyke; Nov 12th, 2007 at 06:29 AM.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Why doesn't this work when compiled?

    Did you simply copy it to your friends computer or did you do a formal installation?

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    Code:
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)

    This function is returning 0 when compiled, but it returns a number when it's in the IDE.

    I've tried replacing PROCESS_QUERY_INFORMATION with other things such as &H1F0FFF and &H100000. Nothing works when it's compiled, however they all work when in the IDE.

    What's happening here!?


    I copied the EXE to my friends computer using msn messenger compressed in winrar.
    Last edited by Slyke; Nov 12th, 2007 at 07:02 AM.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Why doesn't this work when compiled?

    Create an installation and setup package and install it on his machine. It will probably make a difference.

    Windows based programs have long had a consistent tendency not to work if just copied.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    Same error.


    Also, it still does not work on my system either.


    Why does the OpenProcess API return false when it's compiled? That's where the problem is.

    Does the code work for you if you compile it?

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

    Re: Why doesn't this work when compiled?

    are you running vista under a limited account?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    Windows XP Home Edition, Administrator Account.

    Friend was running XP Professional, Administrator Account.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    Does anyone have an alternative?

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why doesn't this work when compiled?

    Could it be a timing issue. When compiled the app will run faster as its not in the ide or loading debugging symbols. Did you take the "On Error Resume Next" out?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    Quote Originally Posted by RobDog888
    Could it be a timing issue. When compiled the app will run faster as its not in the ide or loading debugging symbols. Did you take the "On Error Resume Next" out?
    Yes, took out the On Error Resume Next, Hmmm... how long do you think it needs? I tried looping:

    Code:
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
    Until hProcess became more then 1, but after about 10 seconds i gave up. It shouldn't be taking 10 seconds... should it?

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why doesn't this work when compiled?

    No and are you sure it was still looping as you have allot of DoEvents in there which could interfere with it. What error message do you get, if any?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    Code:
    Do
    
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
    
    Loop Until hProcess >= 1
    
    MsgBox hProcess
    That's the coding i used. Now it's even stranger.

    When i run this when compiled it now returns 148 ALWAYS, the program shows shows up in the taskbar, but doesn't make an appearance on the screen. Then it ends =S.

    When run in the IDE, it says any number (Usually above 1000) and works fine.

    There's no error at all... it hasn't come back. This is seriously confusing me. I've used the same code and am getting different responses. Have you tried it? You can use any file as the resource file.

    I placed the DoEvents in so that it had time to finish extracting the EXE before it tried to execute it. Do you think this might be causing problems?

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why doesn't this work when compiled?

    It could be. Maybe its not finished extracting the exe and could be the reason for it partially running.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Why doesn't this work when compiled?

    OK, i commented out the line that deletes the EXE...

    Tried running the actual exe and it DOESN'T work when it's extracted compiled. How ever the EXE does run when extracted inside the IDE.

    It is only for this one specific EXE... other EXEs extract fine!

    The exe itself is 6.33 MBs and is a game of pong, it was created in DarkBasic... looks like it uses either OpenGL or DirectX graphics... is 3D in a window (Not full screen). Don't know why it won't work when extracted compiled though =S.

    Oh well... at least we know what's causing the wierdness now...

    Thanks.

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Why doesn't this work when compiled?

    It could be a filesize limit on the resource. Check your other files for their sizes and see if the one that fails if it is the largest. If so then that is your issue. You really should be using an installer for this as there is no file size limits.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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