One-day Windows API training (88) enumprocesses Function

Source: Internet
Author: User
One-day Windows API training (88) enumprocesses Function What if an error occurs when the software you developed runs on the user? Of course, you want to generate a report for the running environment information in case of an error, and then email it back to view it. Here we will introduce a function that can locate all the processes in the runtime environment and output the information of each process. Of course, this function can also be used in antivirus software to view suspicious process information.

The enumprocesses function is declared as follows:

Bool
Winapi
Enumprocesses (
DWORD * lpidprocess,
Dword cb,
DWORD * cbneeded
);
Lpidprocess is an array that stores process IDs.
CB is the size of the number of Process Groups.
Cbneeded is the size of the returned process array.

An example of calling a function is as follows:
#001 // obtain all processes of the system.
#002 // Cai junsheng 2007/12/12 QQ: 9073204 Shenzhen
#003 void testenumprocesses (void)
#004 {
#005 //
#006 const int nbufsize = 512;
#007 tchar chbuf [nbufsize];
#008 zeromemory (chbuf, nbufsize );
#009
#010 //
#011 DWORD dwprocs [1, 1024*2];
#012 DWORD dwneeded;
#013
#014 // enumerate all process IDs.
#015 if (! Enumprocesses (dwprocs, sizeof (dwprocs), & dwneeded ))
#016 {
#017 // output error information.
#018 wsprintf (chbuf, _ T ("enumprocesses failed (% d)./N"), getlasterror ());
#019 outputdebugstring (chbuf );
#020
#021 return;
#022}
#023
#024 // calculate the number of process IDs.
#025 DWORD dwproccount = dwneeded/sizeof (DWORD );
#026
#027 wsprintf (chbuf, _ T ("enumprocesses count (% d)./N"), dwproccount );
#028 outputdebugstring (chbuf );
#029
#030}What if an error occurs when the software you developed runs on the user? Of course, you want to generate a report for the running environment information in case of an error, and then email it back to view it. Here we will introduce a function that can locate all the processes in the runtime environment and output the information of each process. Of course, this function can also be used in antivirus software to view suspicious process information.

The enumprocesses function is declared as follows:

Bool
Winapi
Enumprocesses (
DWORD * lpidprocess,
Dword cb,
DWORD * cbneeded
);
Lpidprocess is an array that stores process IDs.
CB is the size of the number of Process Groups.
Cbneeded is the size of the returned process array.

An example of calling a function is as follows:
#001 // obtain all processes of the system.
#002 // Cai junsheng 2007/12/12 QQ: 9073204 Shenzhen
#003 void testenumprocesses (void)
#004 {
#005 //
#006 const int nbufsize = 512;
#007 tchar chbuf [nbufsize];
#008 zeromemory (chbuf, nbufsize );
#009
#010 //
#011 DWORD dwprocs [1, 1024*2];
#012 DWORD dwneeded;
#013
#014 // enumerate all process IDs.
#015 if (! Enumprocesses (dwprocs, sizeof (dwprocs), & dwneeded ))
#016 {
#017 // output error information.
#018 wsprintf (chbuf, _ T ("enumprocesses failed (% d)./N"), getlasterror ());
#019 outputdebugstring (chbuf );
#020
#021 return;
#022}
#023
#024 // calculate the number of process IDs.
#025 DWORD dwproccount = dwneeded/sizeof (DWORD );
#026
#027 wsprintf (chbuf, _ T ("enumprocesses count (% d)./N"), dwproccount );
#028 outputdebugstring (chbuf );
#029
#030}

Related Article

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.