MoonLight MoonLight - 1 year ago 63
C++ Question

'GetProcessIdOfThread': identifier not found

Here is my codes in stdafx.h :

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently

#pragma once

#define _WIN32_WINNT 0x0502

#include "winsock2.h"
#include "windows.h"
#include "stdio.h"
#include "Iphlpapi.h"
#include <psapi.h>
#include "Ntsecapi.h"
#include "txdtc.h"
#include "xolehlp.h"
#include <iostream>
#include <tchar.h>

// TODO: reference additional headers your program requires here

As you see i have included "windows.h"

And here is main codes :

#include "stdafx.h"
if (hThread && dwRpcssPid == GetProcessIdOfThread(hThread))

My errors are :

'GetProcessIdOfThread': identifier not found

IntelliSense: identifier "GetProcessIdOfThread" is undefined

How can i fix these errors?

Answer Source

The function is not available with _WIN32_WINNT values less than 0x0600 AKA _WIN32_WINNT_VISTA. If you change your code this way, you will get it working:

//#define _WIN32_WINNT  0x0502
#define _WIN32_WINNT  0x0600

The function is available since Vista, to target Vista+ you should have this value defined respectively.

To target latest versions of API with current SDK, you can simply include SDKDDKVer.h and those values will be defined for you/

//#define _WIN32_WINNT  0x0502
#include <SDKDDKVer.h>

See also:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download