#include <iostream>
#include <cstdlib>
using namespace std;
typedef unsigned int DWORD;
typedef void VOID;
typedef wchar_t WCHAR;
struct _POWER_BROADCAST
{
DWORD Message;
DWORD Flags;
DWORD Length;
WCHAR ptr[1];
};
struct _POWER_BROADCAST_POWER_INFO
{
int data;
};
int main()
{
// 重點是這裡配置的長度
_POWER_BROADCAST* realObject =
(_POWER_BROADCAST*)malloc(sizeof(_POWER_BROADCAST) + sizeof(_POWER_BROADCAST_POWER_INFO));
realObject->Message = 7788;
realObject->Length = 123;
_POWER_BROADCAST_POWER_INFO *Data =
(_POWER_BROADCAST_POWER_INFO *)realObject->ptr;
Data->data = 5566;
//先印出message, 成功
cout<<realObject->Message<<endl;
_POWER_BROADCAST_POWER_INFO* ptr2 =
(_POWER_BROADCAST_POWER_INFO*)realObject->ptr;
cout<<ptr2->data;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgdW5zaWduZWQgaW50IERXT1JEOwp0eXBlZGVmIHZvaWQgVk9JRDsKdHlwZWRlZiB3Y2hhcl90IFdDSEFSOwoKc3RydWN0IF9QT1dFUl9CUk9BRENBU1QKewogICAgRFdPUkQgICAgICAgTWVzc2FnZTsKICAgIERXT1JEICAgICAgIEZsYWdzOwogICAgRFdPUkQgICAgICAgTGVuZ3RoOwogICAgV0NIQVIgICAgICAgcHRyWzFdOwp9OwoKc3RydWN0IF9QT1dFUl9CUk9BRENBU1RfUE9XRVJfSU5GTwp7CiAgICBpbnQgZGF0YTsKfTsKCmludCBtYWluKCkKewogICAgLy8g6YeN6bue5piv6YCZ6KOh6YWN572u55qE6ZW35bqmCiAgICBfUE9XRVJfQlJPQURDQVNUKiByZWFsT2JqZWN0ID0KICAgICAgICAoX1BPV0VSX0JST0FEQ0FTVCopbWFsbG9jKHNpemVvZihfUE9XRVJfQlJPQURDQVNUKSArIHNpemVvZihfUE9XRVJfQlJP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