Home > Back-end >  error C2061: syntax error : identifier 'VAULT_ELEMENT_TYPE'
error C2061: syntax error : identifier 'VAULT_ELEMENT_TYPE'

Time:06-28

Here is my c code "vault.c"

#include "main.h"

HMODULE vaultcli_addr;
typedef HANDLE HVAULT;
#define VAULT_ENUMERATE_ALL_ITEMS 512

enum VAULT_SCHEMA_ELEMENT_ID {
    ElementId_Illegal = 0,
    ElementId_Resource = 1,
    ElementId_Identity = 2,
    ElementId_Authenticator = 3,
    ElementId_Tag = 4,
    ElementId_PackageSid = 5,
    ElementId_AppStart = 0x64,
    ElementId_AppEnd = 0x2710
};

enum VAULT_ELEMENT_TYPE {
    ElementType_Boolean = 0,
    ElementType_Short = 1,
    ElementType_UnsignedShort = 2,
    ElementType_Integer = 3,
    ElementType_UnsignedInteger = 4,
    ElementType_Double = 5,
    ElementType_Guid = 6,
    ElementType_String = 7,
    ElementType_ByteArray = 8,
    ElementType_TimeStamp = 9,
    ElementType_ProtectedArray = 0xA,
    ElementType_Attribute = 0xB,
    ElementType_Sid = 0xC,
    ElementType_Last = 0xD,
    ElementType_Undefined = 0xFFFFFFFF
};

typedef struct _VAULT_BYTE_BUFFER {
    DWORD Length;
    PBYTE Value;
} VAULT_BYTE_BUFFER, * PVAULT_BYTE_BUFFER;

typedef struct _VAULT_ITEM_DATA {
    DWORD SchemaElementId;
    DWORD unk0;
    VAULT_ELEMENT_TYPE Type; //Line 44
    DWORD unk1;
    union {
        BOOL Boolean;
        SHORT Short;
        WORD UnsignedShort;
        LONG Int;
        ULONG UnsignedInt;
        DOUBLE Double;
        GUID Guid;
        LPWSTR String;
        VAULT_BYTE_BUFFER ByteArray;
        VAULT_BYTE_BUFFER ProtectedArray;
        DWORD Attribute;
        DWORD Sid;
    } data;
} VAULT_ITEM_DATA, * PVAULT_ITEM_DATA;

msvc compiler gives the error:

1>vault.c(44): error C2061: syntax error : identifier 'VAULT_ELEMENT_TYPE'
1>vault.c(60): error C2059: syntax error : '}'
1>vault.c(65): error C2061: syntax error : identifier 'PVAULT_ITEM_DATA'
1>vault.c(66): error C2061: syntax error : identifier 'Identity'
1>vault.c(66): error C2059: syntax error : ';'
1>vault.c(67): error C2061: syntax error : identifier 'Authenticator'
1>vault.c(67): error C2059: syntax error : ';'

I am compiling as C code, i can't figure out the error.
code is taken from here: https://github.com/twelvesec/passcat/blob/master/passcat/libvaultie.cpp

Please help me point out the error. The error starts on line 44.

CodePudding user response:

struct and enum types have their own namespace, so you have to use struct TypeName and enum TypeName instead of just TypeName.

enum VAULT_ELEMENT_TYPE { ... };

enum VAULT_ELEMENT_TYPE vet;

Alternatively you could create a type using typedef.

typedef enum { ... } VAULT_ELEMENT_TYPE;

VAULT_ELEMENT_TYPE vet;

Nothing stops you from creating both.

enum VAULT_ELEMENT_TYPE { ... };
typedef enum VAULT_ELEMENT_TYPE VAULT_ELEMENT_TYPE;

enum VAULT_ELEMENT_TYPE vet;  // ok
VAULT_ELEMENT_TYPE vet;       // Also ok

You can even create both at once.

typedef enum VAULT_ELEMENT_TYPE { ... } VAULT_ELEMENT_TYPE;
  • Related