Incorporated some of the suggestions and there isn't one byte less in the
.exe.
.data
ProcessNameToSearchFor BYTE "C:\PROGRAM FILES\NETSCAPE\NETSCAPE\NETSCP.EXE", 0
ProcessNameLength equ $ - ProcessNameToSearchFor-1 ; length not including null-termination!
;ProcessNameLength DWORD 45 ; length not including null-termination
.code
start:
main proc
LOCAL buffer[260]:BYTE
call TestAppRunning ; see if Netscape is running, if so exit
invoke GetCL,1,ADDR buffer
fn ShellExecute,0,"open",ADDR buffer,NULL,NULL,SW_SHOWNORMAL
invoke ExitProcess,0
main endp
align 4
TestAppRunning proc syscall
LOCAL Process:PROCESSENTRY32, SnapShot:DWORD
comment * -----------------------------------------------------------------------------
Test if application is already running. App name wanted and its length are
coded in the .data section.
On exit:
EAX = 0 if not running or unsuccessful, else nonzero
EBX/EBP/EDI/ESI are preserved.
----------------------------------------------------------------------------- *
push ebx
push edi
push esi
invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
test eax, eax
jz AppNotRunning ; unable to create SnapShot
mov SnapShot, eax
mov Process.dwSize, (SIZEOF PROCESSENTRY32)
invoke Process32First, SnapShot, ADDR Process ; return first process handle
TestValidHandle:
test eax, eax
jz CloseSnapHandle
TestProcessName:
xor eax, eax ; counter for name length
lea esi, Process.szExeFile
lea edi, ProcessNameToSearchFor
@@:
inc eax
.exe.
.data
ProcessNameToSearchFor BYTE "C:\PROGRAM FILES\NETSCAPE\NETSCAPE\NETSCP.EXE", 0
ProcessNameLength equ $ - ProcessNameToSearchFor-1 ; length not including null-termination!
;ProcessNameLength DWORD 45 ; length not including null-termination
.code
start:
main proc
LOCAL buffer[260]:BYTE
call TestAppRunning ; see if Netscape is running, if so exit
invoke GetCL,1,ADDR buffer
fn ShellExecute,0,"open",ADDR buffer,NULL,NULL,SW_SHOWNORMAL
invoke ExitProcess,0
main endp
align 4
TestAppRunning proc syscall
LOCAL Process:PROCESSENTRY32, SnapShot:DWORD
comment * -----------------------------------------------------------------------------
Test if application is already running. App name wanted and its length are
coded in the .data section.
On exit:
EAX = 0 if not running or unsuccessful, else nonzero
EBX/EBP/EDI/ESI are preserved.
----------------------------------------------------------------------------- *
push ebx
push edi
push esi
invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
test eax, eax
jz AppNotRunning ; unable to create SnapShot
mov SnapShot, eax
mov Process.dwSize, (SIZEOF PROCESSENTRY32)
invoke Process32First, SnapShot, ADDR Process ; return first process handle
TestValidHandle:
test eax, eax
jz CloseSnapHandle
TestProcessName:
xor eax, eax ; counter for name length
lea esi, Process.szExeFile
lea edi, ProcessNameToSearchFor
@@:
inc eax
If the code section is greater than 4K, you'll need to reduce code below a 4K boundary. If the code section is less than 4K, the .exe won't be reduced by programming - you'll need to set some linker options. I don't bother with this, so I'll let someone else give the linker settings.
If the code section is greater than 4K, you'll need to reduce code below a 4K boundary. If the code section is less than 4K, the .exe won't be reduced by programming - you'll need to set some linker options. I don't bother with this, so I'll let someone else give the linker settings.
It was just an observation. The next time a poster posts something
at 5 a.m., I'll consider that they will forget some things. :-)
I do want to get rid of code I don't need, but it's size and speed are fine
for me.