enumerate threads

Just starting out? Need help? Post your questions and find answers here.
tonnelier
User
User
Posts: 45
Joined: Mon May 03, 2004 10:34 pm
Location: France

enumerate threads

Post by tonnelier »

I know how to enumerate processes (createtollhelpsnapshot, etc...)
But how can i enumerate threads, and know for a given thread, to which process it is attached?

thank for responses
tonnelier
User
User
Posts: 45
Joined: Mon May 03, 2004 10:34 pm
Location: France

Post by tonnelier »

:!: Stupid i am!!
I've not seen that there are thread32first, thread32next functions too.
So the problem is solved.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

...,

Because you found ToolHelp.dll exists you are not stupid !
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
tonnelier
User
User
Posts: 45
Joined: Mon May 03, 2004 10:34 pm
Location: France

Post by tonnelier »

thanks for this little recomfort!

I've asked earlier if it was possible to pause a process.
Eventually, it's possible, simply by using suspendthread_ for all threads attached to the process. Works fine. (and resumethread_ too)

(If i don't mistake, even if a process don't explicitly create a thread, there is a primary thread attached to it. Threads are the entities, above processes, with which the system manages for the access to the processor)
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

Maybe you scattered me with this DLL ...

HELP me in finding the args to throw in this dll ... I can't find the way to access it well ...
Rgrds
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
tonnelier
User
User
Posts: 45
Joined: Mon May 03, 2004 10:34 pm
Location: France

Post by tonnelier »

Here is a procedure to suspend a process whose id is pid:

Code: Select all

Structure thread32
size.l
use.l
idth.l
parentid.l
base.l
delta.l
flags.l
EndStructure

openlibrary(0,"kernel32.dll")

Procedure pause(pid)

thread.thread32

snap = CallFunction (0, "CreateToolhelp32Snapshot",4,0)
If snap

thread\size=SizeOf(thread32)
CallFunction(0,"Thread32First",snap,@thread)

If thread\parentid=pid
  h=CallFunction(0,"OpenThread",2,0,thread\idth)
  SuspendThread_(h)
  CloseHandle_(h)
EndIf

While CallFunction(0,"Thread32Next",snap,@thread)

If thread\parentid=pid
  h=CallFunction(0,"OpenThread",2,0,thread\idth)
  SuspendThread_(h)
  CloseHandle_(h)
EndIf

Wend

EndIf

EndProcedure
and the procedure to resume

Code: Select all

Procedure resume(pid)

thread.thread32

snap = CallFunction (0, "CreateToolhelp32Snapshot",4,0)
If snap

thread\size=SizeOf(thread32)
CallFunction(0,"Thread32First",snap,@thread)

If thread\parentid=pid
  h=CallFunction(0,"OpenThread",2,0,thread\idth)
  ResumeThread_(h)
  CloseHandle_(h)
EndIf

While CallFunction(0,"Thread32Next",snap,@thread)

If thread\parentid=pid
  h=CallFunction(0,"OpenThread",2,0,thread\idth)
  ResumeThread_(h)
  CloseHandle_(h)
EndIf

Wend

EndIf
EndProcedure
for the constants, i use winapi program.
pvmichael
New User
New User
Posts: 4
Joined: Sat May 15, 2004 12:52 pm

Post by pvmichael »

Thank you very much, this is exactly what i was searching for!
Post Reply