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();
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.