0

Is it possible for an attribute of a 'struct' to host multiple structures?

Example, I need the attribute LPWFSPINFDK lppFDKs; which is part of the struct _wfs_pin_func_key_detail, receive multiple structs _wfs_pin_fdk.

I'm trying this way, compiles, 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; //I want to receive the structs here
} WFSPINFUNCKEYDETAIL, * LPWFSPINFUNCKEYDETAIL;
2501
  • 25,460
  • 4
  • 47
  • 87
Matheus Cardozo
  • 135
  • 1
  • 7
  • Please post the compile or runtime error that you are getting. – Emmanuel Mathi-Amorim Mar 08 '17 at 02:15
  • There is no mistake, I just want to know how I can do it. – Matheus Cardozo Mar 08 '17 at 02:19
  • In your code example you are setting up all these pointers to things on the stack. Once the function that sets those up returns, they are gone, and using any of those pointers will result in undefined behaviour. You should be using `malloc` (or `realloc`) to set up the block `lppFDKs`, and then assign items to it. If you use one less redirection, you can store structures by value there, rather than as pointers. (i.e. take the `*` off `lppFDKs`) – paddy Mar 08 '17 at 02:22
  • In practice, how would I do this? – Matheus Cardozo Mar 08 '17 at 02:26
  • See xfs documentation. You also need to allocate lppFDKs with XFS allocators if you want to transfer data outside you code. **Manual CWA 16926-6** lppFDKs **Pointer to an array of pointers** to WFSPINFDK structures. It is the responsibility of the application to identify the mapping between the FDK code and the physical location of the FDK. lppFDKs is NULL if no FDKs are requested or supported. – Alex.D.Alexeev Mar 08 '17 at 07:38

0 Answers0