2,643
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
void Wait()
{
char w;
cin>>w;
}
struct Data
{
char name[20];
int length;
};
struct DataItem
{
Data data;
DataItem *pNext;
};
int _tmain(int argc, _TCHAR* argv[])
{
DataItem* item = static_cast<DataItem*>(::HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DataItem)));
sprintf(item->data.name,"ipod");
item->data.length = 12;
item->pNext = 0;
cout<<item->data.name<<endl;
cout<<item->data.length<<endl;
cout<<item<<endl;
cout<<&(item->data)<<endl;
bool success = ::HeapFree(::GetProcessHeap(),0,&(item->data));
///如果换成这样呢
//DataItem *p = CONTAINING_RECORD(&(item->data),DataItem,data);
//cout<<p<<endl;
//bool success = ::HeapFree(::GetProcessHeap(),0,p);
cout<<success<<endl;
Wait();
return 0;
}