Windows API函数不可用,虽然它应该是
问题描述:
我试图创建一个使用Windows API的符号链接,但CreateSymbolicLink
函数似乎并不存在,即使我包含了windows.h
。Windows API函数不可用,虽然它应该是
我正在使用Qt Creator。除了这个,我可以使用API中的其他功能。
任何人都可以解释为什么吗?
我在Windows 8.1上。
编辑:
我的代码:
#include "windows.h"
bool createSymbolicLink(const int &type, const QString &linkPath, const QString &targetPath) {
DWORD windows_Type = type;
wchar_t* windows_LinkPath = new wchar_t[linkPath.length()];
linkPath.toWCharArray(windows_LinkPath);
wchar_t* windows_TargetPath = new wchar_t[targetPath.length()];
targetPath.toWCharArray(windows_TargetPath);
return CreateSymbolicLinkW(windows_LinkPath, windows_TargetPath, windows_Type) != 0;
}
错误: 'CreateSymbolicLinkW' 没有在此范围
答
CreateSymbolicLink
有Vista的最低要求宣布,为documented at MSDN。
这意味着您需要通过条件定义的方式指定您的目标是Vista和更高版本。你可以在这里找到更多的文档:
因此,您可以在包含Windows头文件之前包含这些定义。
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
如果这没有帮助,那么你已经过时了SDK,并且需要切换到更新的SDK。
我会研究一下,但不应该显示功能吗?或者我必须有条件才能出现? 编辑: 我已经包含了定义,但我仍然无法使用该功能,编译器会引发错误。 – Qub1 2014-09-29 21:16:20
如果您未定义这些条件,则不会声明这些函数。你必须选择更高的Windows版本。否则,您可能会意外链接到您定位的Windows版本上不可用的功能。例如,如果您希望您的代码在Windows XP上运行,则必须找到不同的方法。运行时链接到该功能,只有在该功能可用时。否则,适用于较旧版本的Windows的一些后备代码。 – 2014-09-29 21:18:21
答复已更新。你会有一个过时的SDK。 – 2014-09-29 21:19:51