I want to write program which starts another program (process). I am using MASM64 (ml64.exe) from Visual Studio 2015.
Program doesn't work. Nothing is shown. In debugger I get Access Violation.
I have no idea what is wrong with my code.
My code:
extrn ExitProcess : proc
extrn MessageBoxA : proc
extrn CreateProcessA : proc
PROCESS_INFORMATION struct
hProcess DWORD ?
hThread DWORD ?
dwProcessId DWORD ?
dwThreadId DWORD ?
PROCESS_INFORMATION ends
STARTUPINFOA struct
cb DWORD ?
lpReserved DWORD ?
lpDesktop DWORD ?
lpTitle DWORD ?
dwX DWORD ?
dwY DWORD ?
dwXSize DWORD ?
dwYSize DWORD ?
dwXCountChars DWORD ?
dwYCountChars DWORD ?
dwFillAttribute DWORD ?
dwFlags DWORD ?
wShowWindow WORD ?
cbReserved2 WORD ?
lpReserved2 DWORD ?
hStdInput DWORD ?
hStdOutput DWORD ?
hStdError DWORD ?
STARTUPINFOA ends
.const
MB_ICONINFORMATION equ 40h
ERROR_ALREADY_EXISTS equ 0B7h
NORMAL_PRIORITY_CLASS equ 020h
.data
szText db "This is first application which creates new process using CreateProcessA.", 00h
szCaption db "Information",00h
processInfo PROCESS_INFORMATION <>
startupInfo STARTUPINFOA <>
szProcName db "D:\Apps\SampleApp.exe", 00h
.code
Main proc
;not sure if correct - begin
lea rax, processInfo
lea rbx, startupInfo
sub rsp, 60h
push rax
push rbx
push 00h
push 00h
push NORMAL_PRIORITY_CLASS
push 00h
mov r9, 00h
mov r8, 00h
mov rdx, 00h
lea rcx, szProcName
call CreateProcessA
add rsp, 60h
;not sure if correct - end
sub rsp, 28h
mov r9, MB_ICONINFORMATION
lea r8, szCaption
lea rdx, szText
xor rcx, rcx
call MessageBoxA
add rsp, 28h
Exit:
xor rcx, rcx
call ExitProcess
Main endp
end
build.bat
@echo off
ml64.exe prog1.asm /link /entry:Main /subsystem:windows /defaultlib:"kernel32.Lib" /defaultlib:"user32.Lib"
pause
Thanks in advance for Your help.