'GetProcessIdOfThread':找不到标识符

时间:2015-05-04 11:34:59

标签: c++ winapi visual-studio-2013 windows-7

以下是 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

如你所见,我已经收录了“windows.h”

这是主要代码:

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

我的错误是:

  

'GetProcessIdOfThread':找不到标识符

     

IntelliSense:标识符“GetProcessIdOfThread”未定义

我该如何解决这些错误?

3 个答案:

答案 0 :(得分:5)

_WIN32_WINNT值小于0x0600 AKA _WIN32_WINNT_VISTA时,此功能无法使用。如果您以这种方式更改代码,您将使其正常工作:

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

该功能自Vista开始提供,目标Vista +你应该分别定义这个值。

要使用当前SDK定位最新版本的API,您只需包含SDKDDKVer.h,并为您定义这些值/

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

另见:

答案 1 :(得分:2)

GetProcessIdOfThread的平台要求声明:

  

Windows Vista [仅限桌面应用]

     

Windows Server 2003 [仅限桌面应用]

标题要求说明:

  

Windows 8和Windows Server 2012上的Processthreadsapi.h

所以:

  1. 确保您的Windows SDK是最新的
  2. 确保您已指定platform requirements properly
  3. 确保您包含正确的头文件。

答案 2 :(得分:1)

如果您使用的是Windows 8,则需要包含:Processthreadsapi.h

请参阅标题部分中的MSDN引用。