【问题标题】:'GetProcessIdOfThread': identifier not found'GetProcessIdOfThread':找不到标识符
【发布时间】:2015-07-13 18:43:42
【问题描述】:

这是我在 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”未定义

如何解决这些错误?

【问题讨论】:

  • 只是是一个 IntelliSense 错误吗?如果是这样,那么您可以无视它。除此之外,您不会碰巧在与您的stdafx.h 相同的目录中有一个名为windows.h 的文件,对吗?或者,在与GetProcessIdOfThread() 相同的文件中添加#include &lt;Windows.h&gt; 会消除错误吗?
  • 很抱歉,请查看我的问题。

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


【解决方案1】:

该函数不适用于 _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>

另见:

【讨论】:

  • 感谢所有答案,但这一个解决了我的问题。
  • R 怎么和你聊天?
  • @MoonLight:没有聊天,但你可以在我的个人资料中找到网站上的电子邮件地址。
【解决方案2】:

GetProcessIdOfThread 的平台要求说明:

Windows Vista [仅限桌面应用]

Windows Server 2003 [仅限桌面应用]

标题要求说明:

Windows 8 和 Windows Server 2012 上的 Processthreadsapi.h

所以:

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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

    • 我使用的是 Windows 7 - 我添加了这一行:#include "Processthreadsapi.h" 但该错误仍然存​​在!!!
    • 我使用的是 Windows 8,据说,我无法重现您的问题。我可以建议的是关闭视觉工作室,删除 .sdf (这是智能感知),看看这是否有帮助。您也可以尝试单击 Go To Definition 以查看链接器是否正常。这可能只是一个智能感知错误。
    猜你喜欢
    • 1970-01-01
    • 2013-03-17
    • 2015-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多