No object has been created and you are modifying the members of the struct by a pointer that points to nothing. This is undefined behavior.
The mistake is in:
LPWFSPTRRETRACTBINS RetractBins;
RetractBins->wRetractBin = WFS_PTR_RETRACTBININSERTED;
RetractBins->usRetractCount = 0;
Here RetractBins
is a pointer _wfs_ptr_retract_bins
pointing to no object.
The right thing is to first create an object WFSPTRRETRACTBINS
and then pass your memory address to the pointer RetractBins
.
The correct code would be: (unused windows. h)
#include <iostream>
#define WFS_PTR_RETRACTBININSERTED 5
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef struct _wfs_ptr_retract_bins
{
WORD wRetractBin;
USHORT usRetractCount;
} WFSPTRRETRACTBINS, *LPWFSPTRRETRACTBINS;
typedef struct _wfs_ptr_status
{
LPWFSPTRRETRACTBINS *lppRetractBins;
} WFSPTRSTATUS, *LPWFSPTRSTATUS;
int main()
{
WFSPTRSTATUS PtrStatus;
WFSPTRRETRACTBINS objRetractBins; //primeiro criar um objeto válido na memoria
LPWFSPTRRETRACTBINS RetractBins;
RetractBins = &objRetractBins; // agora sim, o ponteiro RetractBins aponta para um objeto
RetractBins->wRetractBin = WFS_PTR_RETRACTBININSERTED;
RetractBins->usRetractCount = 15;
PtrStatus.lppRetractBins = &RetractBins;//AQUI QUERO PASSAR
std::cout << (*PtrStatus.lppRetractBins)->wRetractBin << std::endl; //lppRetractBins é um ponteiro para ponteiro, é necessário dereferencialo.
}
There is still no context to what you are doing. This is not working?
– Maniero
It n accuses build error, but I know it doesn’t work.
– Matheus Cardozo
Ask the question the error. Give full information so we can help.
– Maniero