Windows C ++ obtains the number of threads of a process.

Source: Internet
Author: User

 

We mainly want to implement a function to determine whether the process is multi-threaded. Different content is displayed as needed.

I don't know yet...

Mark.

After studying it, I went to the snow forum and found the following information. There is an example.

Http://bbs.pediy.com/showthread.php? T = 98078

Then I finally wrote a simple example After pondering for a long time.

Http://bbs.pediy.com/showthread.php? P = 1098221 # post1098221

Http://baike.baidu.com/view/589425.htm here also can.

# Include <tlhelp32.h> Void  Testprocessgetthreadnumber (){  Int I = 0  ; Char Buff [ 9  ]; Processentry32 pe32; pe32.dwsize = Sizeof  (Pe32); handle hprocesssnap =: Createconlhelp32snapshot (th32cs_snapprocess, 0  );  If (Hprocesssnap = Invalid_handle_value) {printf (  "  Createconlhelp32snapshot call failed. \ n  "  ); Return  ;} Bool bmore =: Process32first (hprocesssnap ,& Pe32); handle hprocess; printf (  "  %-30 S %-20 S %-20 S %-15s \ n  " , "  Szexefile  " , "  Th32processid  " , "  Th32parentprocessid  " , "  Cntthreads  "  );  While  (Bmore) {printf (  "  %-30 s  "  , Pe32.szexefile); printf (  "  %-20d  "  , Pe32.th32processid); printf (  "  %-20d "  , Pe32.th32parentprocessid );  //  Display the number of threads of a process Printf ( "  %-15D \ n  "  , Pe32.cntthreads); bmore = Process32next (hprocesssnap ,& Pe32); I ++ ;  //  Pe32.th32moduleid  } Printf (  "  Process count: % d \ n "  , I); System (  "  Pause  "  ); Exit (  0  );} 

 

 

 

Another problem encountered today is that string. Data () is used to obtain an int integer using atoi (). The range is too small. You need to use functions such as atoll, but no.

One of the shlwapi. h libraries can use strtoint64a.

Defined:

 
Lwstdapi _ (bool) strtoint64exa (_ in lpcstr pszstring, _ in stif_flags dwflags, _ out Longlong * pllret );

Set the second parameter to 0. 1 is hexadecimal. The first is the target C string address. The third parameter is the address of the target long. The returned value is true or false to determine whether the operation is successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.