Attribute of a struct to receive multiple structs

0

Can an attribute of a struct receive multiple structs?

For example, I need the LPWFSPINFDK lppFDKs; attribute that is part of the _wfs_pin_func_key_detail struct to receive multiple _wfs_pin_fdk structs.

I'm trying this way, compile, but the final program does not recognize:

    WFSPINFUNCKEYDETAIL PinFunKeyDetail;

    WFSPINFDK ObjPinKey;
    LPWFSPINFDK PinKey;
    PinKey = &ObjPinKey;

    PinKey->ulFDK = WFS_PIN_FK_FDK01;
    PinKey->usXPosition = 5;
    PinKey->usYPosition = 5;

    PinFunKeyDetail.lppFDKs = &PinKey;

STRUCT: _wfs_pin_fdk

typedef struct _wfs_pin_fdk
{
    ULONG               ulFDK;
    USHORT              usXPosition;
    USHORT              usYPosition;
} WFSPINFDK, * LPWFSPINFDK;

STRUCT: _wfs_pin_func_key_detail

typedef struct _wfs_pin_func_key_detail
{
    ULONG               ulFuncMask;
    USHORT              usNumberFDKs;
    LPWFSPINFDK       * lppFDKs; //Aqui recebo as structs
} WFSPINFUNCKEYDETAIL, * LPWFSPINFUNCKEYDETAIL;
    
asked by anonymous 08.03.2017 / 00:16

1 answer

0

Responding: An attribute of a struct is allowed to receive multiple structs . The attribute you are referring to, however, is just a pointer, not a container. Pointers can not get multiple structs , just addresses of these.

Something that can get multiple structs would be a std::vector<_wfs_pin_fdk> .

For the excerpts posted, LPWFSPINFDK is a type set as pointer to _wfs_pin_fdk .

In class _wfs_pin_func_key_detail , the lppFDKs attribute is a pointer to LPWFSPINFDK .

That is: lppFDKs is a pointer to pointer to _wfs_pin_fdk .

Maybe you forgot to set usNumberFDKs ? By inferring by variable name, it seems to store how many pointers to _wfs_pin_fdk are stored in lppFDKs .

Changing your example so that lppFDKs points to an array of multiple pointers:

WFSPINFUNCKEYDETAIL PinFunKeyDetail;

//três _wfs_pin_fdk
WFSPINFDK PinKeyA;
WFSPINFDK PinKeyB;
WFSPINFDK PinKeyC;

//(..algum código manipulado os _wfs_pin_fdk..)

//endereço dos três _wfs_pin_fdk , em array
LPWFSPINFDK PinKeys[3] = {
    &PinKeyA,
    &PinKeyB,
    &PinKeyC
};

//passa para lppFDKs o endereço da array de LPWFSPINFDK
PinFunKeyDetail.lppFDKs = PinKeys;

//palpite: esse atributo indica quandos elementos são apontados por lppFDKs 
PinFunKeyDetail.usNumberFDKs = 3;

You said that

  

the final program does not recognize

But this is very vague, I do not know what program you are referring to. Here is the online code by compiling Ideone .

    
08.03.2017 / 05:17