ms c++ get pid of current process

a 夏天 提交于 2019-11-28 11:53:08

The GetCurrentProcessId function will do this.

Having grown accustomed to seeing yards and yards of code to accomplish seemingly straightforward tasks, I was pleasantly surprised at the directness of GetCurrentProcessId. Earlier today, I watched it run in a debugger, when I was following a new bit of code in a DllMain routine that combines the process ID with an embedded GUID to create a locally unique name for a mutex.

Following is the entire routine, all three machine instructions.

mov         eax,fs:[00000018]
mov         eax,dword ptr [eax+20h]
ret

BTW, two other blessedly simple Windows API functions are GetLastError and SetLastError; indeed, both are quite similar to this one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!