找不到 Win32 API 函数 [英] Win32 API Functions not Found

查看:52
本文介绍了找不到 Win32 API 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 Ultimate 32 位上使用 DevC++,并且在我的程序中包含了 windows.h 和 psapi.h.到目前为止,除了 GetProcessId 和 DebugActiveProcessStop 之外,我使用的所有 Windows API 都可以正常工作.编译器在这两种情况下都会返回未声明指定函数的情况.但是,当我查看 winbase.h 时,我可以清楚地看到声明了 GetProcessId.即使将鼠标悬停在函数上,也会显示有关结构的信息.那么,为什么编译器似乎无法识别任一函数?

I am usign DevC++ on Windows 7 Ultimate 32 bit and have included windows.h and psapi.h in my program. All the Windows APIs I've used so far ar working except for GetProcessId and DebugActiveProcessStop. The compiler returns in both cases that the specified function is undeclared. However, when I look in winbase.h, I can clearly see that GetProcessId is declared. Even when I hover the mouse over the function, information on the structure is displayed. So, why can't the compiler seem to recognize either function?

推荐答案

使用 Win32 API 标头时,您需要指定目标操作系统的版本.这记录在 MSDN 库<​​/a>中.

When using the Win32 API headers you need to specify what version of the operating system you are targeting. This is documented in the MSDN library.

现在,您应该通过定义 NTDDI_VERSION 来做到这一点.如果您查看 GetProcessId 的文档 您会注意到它需要 Windows XP SP1,因此您至少需要指定 NTDDI_WINXPSP1 作为目标操作系统版本.事实上,由于不再支持 SP1,您最好使用 SP2:

Nowadays, you are supposed to do this by defining NTDDI_VERSION. If you check the documentation for GetProcessId you'll note that it requires Windows XP SP1, so you need to specify at least NTDDI_WINXPSP1 as the target operating system version. In fact since SP1 is no longer supported you're probably better off with SP2:

#define NTDDI_VERSION 0x05010200

过去我发现定义 NTDDI_VERSION 并不总是按预期工作,但希望大多数故障现在都已解决.如果它不起作用,请尝试使用较旧的宏 _WIN32_WINNT,这也在上面给出的链接中进行了记录.在这种情况下,您需要:

In the past I've found that defining NTDDI_VERSION doesn't always work as expected, though hopefully most of the glitches have been ironed out by now. If it doesn't work, try using the older macro _WIN32_WINNT instead, which is also documented at the link given above. In this case you want:

#define _WIN32_WINNT 0x0502

如果您以后需要使用在 Vista 或 Windows 7 中引入的函数,请适当更改 NTDDI_VERSION 或 _WIN32_WINNT 的值.每个函数的 MSDN 库文档说明了它是在哪个版本的操作系统中引入的.

If you later need to use functions that were introduced in Vista or Windows 7, change the value of NTDDI_VERSION or _WIN32_WINNT appropriately. The MSDN library documentation for each function says which version of the operating system it was introduced in.

这篇关于找不到 Win32 API 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆