我正在尝试使用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标头,并且确实存在没有直接引用它的编译错误。我在这里想念什么?

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

最佳答案

SDDL_REVISION_1中定义了sddl.h,但仅当WINAPI_FAMILY被定义为WINAPI_FAMILY_DESKTOP_APP时。 WINAPI_FAMILY的默认值显然是WINAPI_FAMILY_DESKTOP_APP,即winapifamily.h将其定义为WINAPI_FAMILY_DESKTOP_APP(如果尚未定义)。

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

关于c++ - C++ Win API函数“未在此范围内声明”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25276092/

10-10 09:29