C language process information

Source: Internet
Author: User

 

 

1. # include <Windows. h>

2. # include <tchar. h>

3. # include <stdio. h>

4.

5. # define MyAlloc (size) HeapAlloc (GetProcessHeap (), 0, size)

6. # define MyFree (lpMem) HeapFree (GetProcessHeap (), 0, lpMem)

7.

8. typedef struct _ PROCESS_INFO {

9. DWORD dwPid;

10. HANDLE hProcess;

11. DWORD dwPrioClass;

12. DWORD dwHandleCount;

13. DWORD dwAffinityMask;

14. SIZE_T dwWorkingSetSizeMax;

15. SIZE_T dwWorkingSetSizeMin;

16. LPWSTR szwCommandLine;

17. STARTUPINFO sit;

18.} PROCESS_INFO, * LPPROCESS_INFO;

19.

20. HANDLE hMySelf;

21.

22. DWORD GetProcessInfo (LPPROCESS_INFO lppi );

23.

24. int WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){

25. PROCESS_INFO pi;

26. INT argc;

27. WCHAR ** argv;

28. DWORD I;

29. DWORD dwBufferSize = lstrlen (lpCmdLine) + MAX_PATH + 1024;

30. LPSTR szShowBuffer = (LPSTR) MyAlloc (dwBufferSize );

31.

32. hMySelf = hInstance;

33.

34. wsprintf (szShowBuffer, "Start Parameter \ n instance handle: %. 8X, command line parameter: % s, display option: %. 8X", hInstance, lpCmdLine, nCmdShow );

35.

36. MessageBox (NULL, szShowBuffer, "WinMain function parameter", MB_ OK );

37.

38. GetProcessInfo (& pi );

39.

40. argv = CommandLineToArgvW (pi. szwCommandLine, & argc );

41.

42. * szShowBuffer = NULL;

43.

44. for (I = 0; I <argc; I ++ ){

45. DWORD dwBufferSize = lstrlenW (* argv) + 1;

46. LPSTR szMBArgv = MyAlloc (dwBufferSize );

47. WideCharToMultiByte (CP_ACP, NULL, * argv,-1, szMBArgv, dwBufferSize, NULL, NULL );

48. argv ++;

49. lstrcat (szShowBuffer, "\ n ");

50. lstrcat (szShowBuffer, szMBArgv );

51. MyFree (szMBArgv );

52 .}

53. MessageBox (NULL, szShowBuffer, "parameter", MB_ OK );

54. MyFree (szShowBuffer );

55. return 0;

56 .}

57.

58. DWORD GetProcessInfo (LPPROCESS_INFO lppi ){

59. lppi-> dwPid = GetCurrentProcessId ();

60. lppi-> hProcess = GetCurrentProcess ();

61. lppi-> dwPrioClass = GetPriorityClass (hMySelf );

62. GetProcessAffinityMask (hMySelf, & lppi-> dwAffinityMask, NULL );

63. GetProcessWorkingSetSize (hMySelf, & lppi-> dwWorkingSetSizeMin, & lppi-> dwWorkingSetSizeMax );

64. lppi-> szwCommandLine = GetCommandLineW ();

65.

66. GetStartupInfo (& lppi-> sit );

67. return 0;

68 .}

 

This article is from the "Pnig0s" blog

 

 

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.