This program (with some syntax changes) compiles 'flat' with flat assembler.
MASM gives the error...
"INVOKE requires prototype for procedure"
INVOKE Process32First, hSnapShot, offset ProcessEntry
INVOKE Process32Next, hSnapShot, offset ProcessEntry
In kernel32.inc I find only
Process32FirstW
Process32NextW
What to do ?
Here the source for masm32
The zipfile has the source for flatassembler and masm32
include \masm32\include\masm32rt.inc
PROCESSENTRY32 STRUCT
dwSize dd ?
cntUsage dd ?
th32ProcessID dd ?
th32DefaultHeapID dd ?
th32ModuleID dd ?
cntThreads dd ?
th32ParentProcessID dd ?
pcPriClassBase dd ?
dwFlags dd ?
szExeFile db MAX_PATH dup(?)
PROCESSENTRY32 ENDS
TH32CS_SNAPPROCESS equ 2
.data
success db "Runs"
chkfor db "mysqld.exe", 0
hSnapShot dd ?
ProcessEntry PROCESSENTRY32<>
.code
Start:
mov ProcessEntry.dwSize, SIZEOF PROCESSENTRY32
INVOKE CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
mov hSnapShot, eax
INVOKE Process32First, hSnapShot, offset ProcessEntry
NextProcess:
INVOKE lstrcmpi, ProcessEntry.szExeFile, offset chkfor
.if eax == 0
jmp Found
.else
INVOKE Process32Next, hSnapShot, offset ProcessEntry
show_value eax,"next"
jmp NextProcess
.endif
Found:
INVOKE MessageBox, 0,offset success, offset chkfor, MB_ICONQUESTION
jmp Exit
Exit:
INVOKE ExitProcess, 0
end Start
Forgot the zipfile
It's a long story. Check http://masm32.com/board/index.php?action=search;advanced;search=Process32First
JJ,
yes - seems like a long story. I am reading.
Does the story have a happy end ?
If not, I forget the story and use flat assembler for this peace ...
Quote from: clamicun on February 03, 2017, 12:11:01 PMDoes the story have a happy end ?
Not really; there is a reason why I used LoadLibrary & GetProcAddress in my recent example (http://masm32.com/board/index.php?topic=5987.0).
You could rebuild your Kernel32.lib with the correct definitions, but it means that any code based on the new version will be incompatible with the current Masm32 installation :(
It is not really a competition between MASM and FASM, both can produce high quality binary code when written correctly. Which one you use is a matter of experience and taste.
JJ,
your recent example is excellent.
I changed it a bit. It hasn't any output. Only quits with Exitcode 666 if mysqld.exe doesn't run.
Quote from: clamicun on February 03, 2017, 01:00:31 PM
your recent example is excellent.
I changed it a bit. It hasn't any output. Only quits with Exitcode 666 if mysqld.exe doesn't run.
Thanks, but how did Lucifer get involved in this??? For me, it just returns 0=not found or 1=found ::)
Hi clamicun,
Some additional features. You can query any process using the command-line :
test.bat :
@QueryProcess explorer.exe
@echo %ERRORLEVEL%
Process explorer.exe is running.
1
The environment variable ERRORLEVEL is set to 1 if the process is running :
include QueryProcess.inc
.data
text1 db 'Process %s is not running.',13,10,0
text2 db 'Process %s is running.',13,10,0
strtable dd OFFSET text1,OFFSET text2
.data?
buffer db 512 dup(?)
.code
start:
call main
invoke ExitProcess,eax
main PROC USES esi edi
LOCAL pe32:PROCESSENTRY32
LOCAL hProcessSnap:DWORD
invoke ParseCmdLine,OFFSET buffer
cmp eax,2
je @f
ret
@@:
mov eax,OFFSET buffer
mov edi,DWORD PTR [eax+4]
invoke crt__strlwr,edi
lea esi,pe32
invoke CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
mov hProcessSnap,eax
mov pe32.dwSize,SIZEOF PROCESSENTRY32
invoke Process32First,eax,esi
@@:
invoke crt__strlwr,ADDR PROCESSENTRY32.szExeFile[esi]
invoke szCmp,eax,edi
test eax,eax
jnz process_found
invoke Process32Next,hProcessSnap,esi
test eax,eax
jnz @b
invoke CloseHandle,hProcessSnap
xor eax,eax
process_found:
xor edx,edx
xor ecx,ecx
sub ecx,eax
adc edx,edx
push edx
shl edx,2
lea eax,[strtable+edx]
invoke crt_printf,DWORD PTR [eax],edi
pop eax
ret
main ENDP
END start
jj,
that is my special relationhip with Luzifer