User666 User666 - 1 year ago 105
C++ Question

Access struct in union

typedef struct _JOBOBJECT_CPU_RATE_CONTROL_INFORMATION {
DWORD ControlFlags;
union {
DWORD CpuRate;
DWORD Weight;
struct {
WORD MinRate;
WORD MaxRate;
};
};
} JOBOBJECT_CPU_RATE_CONTROL_INFORMATION, *PJOBOBJECT_CPU_RATE_CONTROL_INFORMATION;


https://msdn.microsoft.com/en-us/library/windows/desktop/hh448384.aspx

In the structure above how do I access/change MaxRate? I get ControlFlags like so:

JOBOBJECT_CPU_RATE_CONTROL_INFORMATION cpu;
cpu.ControlFlags = JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP;

Answer Source

In my copy of winnt.h header, the struct is defined as follows:

typedef struct _JOBOBJECT_CPU_RATE_CONTROL_INFORMATION {
    DWORD ControlFlags;
    union {
        DWORD CpuRate;
        DWORD Weight;
    };
} JOBOBJECT_CPU_RATE_CONTROL_INFORMATION, *PJOBOBJECT_CPU_RATE_CONTROL_INFORMATION;

There is indeed no MinRate or MaxRate. My guess is, they might have been added in some later version of the SDK (I only have VC2013 handy at the moment).

Look into getting a fresher copy of the SDK. Meanwhile, LOWORD(CpuRate) and HIWORD(CpuRate) should do.