C++ Win API 函数 'not declared in this scope'

标签 c++ windows winapi

我正在尝试使用 GetNamedSecurityInfo()但我不断遇到超出范围的错误:

main.cpp:25:3: error: 'SDDL_REVISION_1' was not declared in this scope
   SDDL_REVISION_1, DACL_SECURITY_INFORMATION, secDescBuffer, buflen);
   ^
main.cpp:25:68: error: 'ConvertSecurityDescriptorToStringSecurityDescriptor' was not declared in this scope
   SDDL_REVISION_1, DACL_SECURITY_INFORMATION, secDescBuffer, buflen);

代码如下:

#include "windows.h"
#include "sddl.h"
#include "aclapi.h"
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    PACL pACL = NULL;

    DWORD dwRes = 0;
    PSECURITY_DESCRIPTOR pSecDesc = NULL;

    dwRes = GetNamedSecurityInfo(TEXT("C:\\somefile.txt"),
        SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
        NULL, NULL, &pACL, NULL, &pSecDesc);

    if (ERROR_SUCCESS == dwRes) {

        LPTSTR * secDescBuffer = NULL;
        PULONG buflen = NULL;

        dwRes = ConvertSecurityDescriptorToStringSecurityDescriptor(pSecDesc,
            SDDL_REVISION_1, DACL_SECURITY_INFORMATION, secDescBuffer, buflen);

    } else {
        printf("GetNamedSecurityInfo Error %lu\n", dwRes);
    }
    ...

我知道它使用 sddl.h header ,而且它确实存在,没有直接引用它的编译错误。我在这里错过了什么?

编辑:我正在使用 netbeans 和 minGW 工具链。我有 Windows SDK,并且一直在使用其他部分(如示例中所示的 GetNamedSecurityInfo)。

最佳答案

SDDL_REVISION_1sddl.h 中定义,但前提是 WINAPI_FAMILY 定义为 WINAPI_FAMILY_DESKTOP_APPWINAPI_FAMILY 的默认值显然是 WINAPI_FAMILY_DESKTOP_APP,也就是说 winapifamily.h 将其定义为 WINAPI_FAMILY_DESKTOP_APP 如果不是已经定义。

我的最佳猜测是您已将 WINAPI_FAMILY 定义为 WINAPI_FAMILY_DESKTOP_APP 以外的内容。

关于C++ Win API 函数 'not declared in this scope',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25276092/

相关文章:

windows - 小读(重叠,缓冲)的性能优于大连续读的解释?

java - 在不初始化 Java 内部数组的情况下创建数组数组(2D)

android - 无法打开 HAX 设备 (Android)

c# - 如何做 RegAsm 使其涵盖 32 位和 64 位?

windows - 如何正确使用 SSL_read() 和 select()?

python - 文件未发布

c++ - Windows标题中的侵入性定义

c++ - 如何在多个内核中使用 Eigen::Tensor::convolve?

c++ - 我应该处理 WSASend() 可能不会发送所有数据的事实吗?

c++ - 为什么我不能在下面的代码中使用 `pos_type` 返回类型?