3

Is there an easy explanation for what this error means?

error: request for member 'Attributes' in '* printerInfo', which is of pointer type 'PPRINTER_INFO_2 {aka _PRINTER_INFO_2A*}' (maybe you meant to use '->' ?)

PPRINTER_INFO_2* printerInfo = NULL;

    void ChangedPrinter()
    {
       ...
       DWORD attributesPrinterInfo;

       printerInfo = (PPRINTER_INFO_2*) malloc(bufferSize);

       attributesPrinterInfo = printerInfo->Attributes; // error

       free(printerInfo);
    }

What am I doing wrong???

LihO
  • 41,190
  • 11
  • 99
  • 167
msantiago
  • 346
  • 2
  • 4
  • 14
  • Of which type are `AttributesPrinterInfo` and `printerInfo->Atteibutes`? It seems to me that the one is a pointer, the other one is a struct. –  Feb 19 '13 at 19:02
  • The two are of the same type DWORD. attributesPrinterInfo is not a pointer. – msantiago Feb 19 '13 at 19:09

2 Answers2

9

PRINTER_INFO_2 structure is defined as:

typedef struct _PRINTER_INFO_2 {
  // ...
} PRINTER_INFO_2, *PPRINTER_INFO_2;

so PPRINTER_INFO_2 is pointer to PRINTER_INFO_2. When you do

printerInfo = (PPRINTER_INFO_2*) malloc(bufferSize);

printerInfo actually becomes a pointer to pointer to PRINTER_INFO_2. I'm not sure whether this was an intention or just a mistake, but if it's intended to be PPRINTER_INFO_2* then proper usage is:

(*printerInfo)->Attributes
LihO
  • 41,190
  • 11
  • 99
  • 167
0

for Cpp, See this https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91138

Suggesting -> isn't helpful when it already uses it. The right fix-it is to suggest (*pp)->member

indev
  • 125
  • 2
  • 8