C 程序 - 在编译器中标记为未声明的结构 [英] C program - Structure marked as undeclared in compiler

查看:44
本文介绍了C 程序 - 在编译器中标记为未声明的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序来收集有关文件的安全信息并将其转换为人类可读的信息.但是,我在初始化指向结构的指针时遇到了问题:

I am trying to write a program to collect security information about a file and convert it to human readable information. However, I am facing a problem with initializing a pointer to structure:

#include <stdio.h>
#include <aclapi.h>
#pragma comment(lib, "advapi32.lib")
struct file_perms {
    char user_domain[2050];
    unsigned long user_mask;
};
static myfunc (){

PSECURITY_DESCRIPTOR pSD = NULL;
PACL pDACL = NULL;
char *file = "D:/code/test.c";
ACL_SIZE_INFORMATION aclSize;

ULONG result = GetNamedSecurityInfo(file,SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &pDACL, NULL, &pSD);
if (ERROR_SUCCESS != result) {
    printf( "GetNamedSecurityInfo Error %u\n", result );
}
if(pDACL != NULL){printf ("2\n");}
//ACL_SIZE_INFORMATION aclSize = {0};
ZeroMemory(&aclSize, sizeof(ACL_SIZE_INFORMATION));
    if(pDACL != NULL){   
        if(!GetAclInformation(pDACL, &aclSize, sizeof(aclSize),
            AclSizeInformation)){
            printf("GetAclInformation Error \n");
            return 0;
        }
        printf("AceCount %d\n",aclSize.AceCount);
    }
file_perms *fp = new file_perms[aclSize.AceCount];

}

编译时出现以下错误.getnamed.c

While compiling, I am getting the following error. getnamed.c

getnamed.c(34) : error C2065: 'file_perms' : undeclared identifier
getnamed.c(34) : error C2065: 'fp' : undeclared identifier
getnamed.c(34) : error C2065: 'new' : undeclared identifier
getnamed.c(34) : error C2106: '=' : left operand must be l-value
getnamed.c(34) : error C2146: syntax error : missing ';' before identifier 'file
_perms'
getnamed.c(34) : error C2065: 'file_perms' : undeclared identifier
getnamed.c(34) : error C2109: subscript requires array or pointer type

谁能帮我理解为什么 file_perms 被标记为未声明的标识符?虽然它已经被声明为一个结构?

Can someone help me understand why is file_perms marked as undeclared identifier? While it is declared as a structure already?

感谢您的帮助.

推荐答案

你应该有

struct file_perms *fp = new file_perms[aclSize.AceCount];

或在开始时创建类型:

typedef struct file_perms {
    char user_domain[2050];
    unsigned long user_mask;
}file_perm;

以后你可以像这样使用它

and later you can use it like

file_perms *fp;
fp = (file_perms*)malloc(aclSize.AceCount * sizeof(file_perms));

顺便说一句:运算符 new 是 C++ 语法,而不是纯 C,您很可能试图将 C++ 代码编译为 C

BTW : operator new is c++ syntax, not pure C, you are most probably trying to compile C++ code as C

这篇关于C 程序 - 在编译器中标记为未声明的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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