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).




Reply With Quote