c语言进程相关信息
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,"启动参数\n实例句柄:%.8X,命令行参数:%s,显示选项:%.8X",hInstance,lpCmdLine,nCmdShow);
35.
36. MessageBox(NULL,szShowBuffer,"WinMain函数参数",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,"参数",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. }
本文出自 “Pnig0s” 博客
补充:软件开发 , C语言 ,