Retrieving Process ID Of Calling Process.


There are different scenarios where you require to know the Process ID of calling process. This might be parent process where your application is running under the context of explorer or you have defined your custom process by calling CreateProcess / CreateProcessA / CreateProcessW.  

I have created a MFC application and used the below code in one of my custom member function.

     DWORD sai = GetCurrentProcessId();

      WCHAR valueconvert[50];

      swprintf_s(valueconvert, 50, L”%d”, sai);

   MessageBox(valueconvert,L”process id is” ,MB_OK);


I was unable to typecast the value to UINT which would be the 3rd parameter I am passing inside messagebox function. GetCurrentProcessID would store the value into the variable “sai”, further I am using swprintf_s to write formatted to a string and print the value using messagebox.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s