flat assembler
Message board for the users of flat assembler.

Index > Windows > Need help with CreateToolhelp32Snapshot

Author
Thread Post new topic Reply to topic
CFJ0



Joined: 06 Jun 2007
Posts: 9
CFJ0
I don't understand why this wont compile at all :S

This is the compile error:
Code:
flat assembler  version 1.67.26  (1248632 kilobytes memory)
c:\winasm\projects\Test\TestSnapshot32.asm [34]: mov dword [ProcessEntry.dwSize], sizeof.PROCESSENTRY32
error: undefined symbol 'ProcessEntry.dwSize'.    


Code:
format PE GUI 4.0
include '%inc%\win32ax.inc'

struct PROCESSENTRY32
 .dwSize               dd ?
 .cntUsage             dd ?
 .th32ProcessID        dd ?
 .th32DefaultHeapID    dd ?
 .th32ModuleID         dd ?
 .cntThreads           dd ?
 .th32ParentProcessID  dd ?
 .pcPriClassBase       dd ?
 .dwFlags              dd ?
 .szExeFile            rb 260 
ends 

TH32CS_SNAPPROCESS = 0x2

;------------------------------------------------
;Declares
;------------------------------------------------
.data
 SnapHandle     dd ?
 ProcessEntry   PROCESSENTRY32
 szProcessName  db "explorer.exe", 0
 
.code
 Main:
;------------------------------------------------ 
;Create Snapshot of Processes
;------------------------------------------------
  mov dword [ProcessEntry.dwSize], sizeof.PROCESSENTRY32
  invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
  cmp eax, 0
  je Exit
  mov dword [SnapHandle], eax
  invoke Process32First, dword [SnapHandle], ProcessEntry

;------------------------------------------------
;Loop Through All Processes
;------------------------------------------------ 
NextProcess:
  cmp eax, 0
  je Exit
  invoke lstrcmpi, ProcessEntryOwn.szExeFile, szProcessName
  cmp eax, 0
  je Found
  invoke Process32Next, dword [SnapHandle], ProcessEntry
  jmp NextProcess 
;------------------------------------------------
;Show a messagebox if found
;------------------------------------------------
Found:  
 invoke MessageBox, 0, "Process Found!", szProcessName, MB_ICONQUESTION
 jmp Exit
 
;------------------------------------------------
;Exit the loader when done
;------------------------------------------------
Exit:  
  invoke ExitProcess, 0
.end Main
    
Post 07 Apr 2008, 17:13
View user's profile Send private message Reply with quote
wisepenguin



Joined: 30 Mar 2005
Posts: 129
wisepenguin
hello,
the struct macro does not need "." character in.

have a good day
Post 07 Apr 2008, 17:19
View user's profile Send private message Reply with quote
wisepenguin



Joined: 30 Mar 2005
Posts: 129
wisepenguin
ps.
Code:
struct PROCESSENTRY32 
 dwSize               dd ?
 cntUsage             dd ?
 th32ProcessID        dd ?
 th32DefaultHeapID    dd ?
 th32ModuleID         dd ?
 cntThreads           dd ?
 th32ParentProcessID  dd ?
 pcPriClassBase       dd ?
 dwFlags              dd ?
 szExeFile            rb 260
ends
    
Post 07 Apr 2008, 17:19
View user's profile Send private message Reply with quote
CFJ0



Joined: 06 Jun 2007
Posts: 9
CFJ0
Thanks
Post 07 Apr 2008, 17:28
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
This compile fine Wink
Code:
format PE GUI 4.0 
include '%inc%\win32ax.inc' 

struct PROCESSENTRY32 
 .dwSize               dd ? 
 .cntUsage             dd ? 
 .th32ProcessID        dd ? 
 .th32DefaultHeapID    dd ? 
 .th32ModuleID         dd ? 
 .cntThreads           dd ? 
 .th32ParentProcessID  dd ? 
 .pcPriClassBase       dd ? 
 .dwFlags              dd ? 
 .szExeFile            rb 260  
ends  

TH32CS_SNAPPROCESS = 0x2 

;------------------------------------------------ 
;Declares 
;------------------------------------------------ 
.data 
 SnapHandle     dd ? 
 ProcessEntry   PROCESSENTRY32 
 szProcessName  db "explorer.exe", 0 
  
.code 
 Main: 
;------------------------------------------------  
;Create Snapshot of Processes 
;------------------------------------------------ 
  mov dword [ProcessEntry..dwSize], sizeof.PROCESSENTRY32 
  invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0 
  cmp eax, 0 
  je Exit 
  mov dword [SnapHandle], eax 
  invoke Process32First, dword [SnapHandle], ProcessEntry 

;------------------------------------------------ 
;Loop Through All Processes 
;------------------------------------------------  
NextProcess: 
  cmp eax, 0 
  je Exit 
  invoke lstrcmpi, ProcessEntry..szExeFile, szProcessName 
  cmp eax, 0 
  je Found 
  invoke Process32Next, dword [SnapHandle], ProcessEntry 
  jmp NextProcess  
;------------------------------------------------ 
;Show a messagebox if found 
;------------------------------------------------ 
Found:   
 invoke MessageBox, 0, "Process Found!", szProcessName, MB_ICONQUESTION 
 jmp Exit 
  
;------------------------------------------------ 
;Exit the loader when done 
;------------------------------------------------ 
Exit:   
  invoke ExitProcess, 0 
.end Main 
    
Post 07 Apr 2008, 17:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.