Hi,
Can someone please explain to me in non-technical what VB "Bad DLL Calling Convention" Means Stack Frame Mismatch means? I am receiving that error if I use
Form
Module
However, the code in post #12 here works without problems.
The error with the posted code seems to occurs on this line
Located here
Thanks,
Nightwalker
Can someone please explain to me in non-technical what VB "Bad DLL Calling Convention" Means Stack Frame Mismatch means? I am receiving that error if I use
Form
Code:
Option Explicit
Private Running As Boolean
'API Constants
Const SMTO_BLOCK = &H1
Const SMTO_ABORTIFHUNG = &H2
Const WM_NULL = &H0
Const WM_CLOSE = &H10
Const PROCESS_ALL_ACCESS = &H1F0FFF
'API functions
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret&
Public Function GetShortName(ByVal sLongFileName As String) As String
Dim lRetval As Long, sShortPathName As String, iLen As Integer
'Set up buffer area for API function call return
sShortPathName = Space(255)
iLen = Len(sShortPathName)
'Call the function
lRetval = GetShortPathName(sLongFileName, sShortPathName, iLen)
'Strip away unwanted characters.
GetShortName = Left$(sShortPathName, lRetval)
End Function
Public Function ExecCmd(cmdline$)
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
start.dwFlags = STARTF_USESHOWWINDOW 'forces functn to use wShowWindow param below
start.wShowWindow = SW_HIDE 'shelled process is HIDDEN.'Use SW_SHOW etc to run visible
' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
Public Sub Launch()
Dim lngResult As Long
Dim lngReturnValue As Long
' Replace the path and app.name.type with that of the application you want to use
RetVal = ExecCmd("E:\Steam\Steam.exe")
lngReturnValue = SendMessageTimeout(0, WM_NULL, 0&, 0&, SMTO_ABORTIFHUNG And SMTO_BLOCK, 1000, lngResult)
DoEvents
If lngReturnValue Then
Running = True
Else
' Close the host and the client if the client does not respond
DoEvents
Running = False
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
End If
End Sub
Private Sub Command_Click()
Launch
End Sub
Code:
Option Explicit
Public Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadID As Long
End Type
Public Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Public Declare Function CloseHandle Lib "kernel32" _
()
Public Declare Function GetExitCodeProcess Lib "kernel32" _
()
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" _
()
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const NORMAL_PRIORITY_CLASS = &H20
Public Const HIGH_PRIORITY_CLASS = &H80
Public Const SW_HIDE& = 0
Public Const STARTF_USESHOWWINDOW& = &H1
Public Const INFINITE = -1&
Public RetVal As Long
The error with the posted code seems to occurs on this line
Code:
Call GetExitCodeProcess(proc.hProcess, ret&)
Code:
Public Function ExecCmd(cmdline$)
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
start.dwFlags = STARTF_USESHOWWINDOW 'forces functn to use wShowWindow param below
start.wShowWindow = SW_HIDE 'shelled process is HIDDEN.'Use SW_SHOW etc to run visible
' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
Nightwalker