SHGetMalloc函数问题??? ( 积分: 0 )

  • 主题发起人 主题发起人 cyradg
  • 开始时间 开始时间
C

cyradg

Unregistered / Unconfirmed
GUEST, unregistred user!
即在空间命名扩展应用中,要为PIDL分配内存,SHGetMalloc函数居然出现异常,
constructor TPidlMgr.Create
//初始化
begin
inherited Create;
FMalloc :=nil;
SHGetMalloc(FMalloc);
end;

function TPidlMgr.CreateIDLits: PITEMIDLIST;
var
pidl,pTmp:PITEMIDLIST;
uSize:WORD;
begin
uSize :=sizeof(ITEMIDLIST)+4;
pidl :=FMalloc.Alloc(uSize+sizeof(ITEMIDLIST))
//居然出错,系统报内存不可写
if pidl<>nil then
begin
pTmp :=pidl;
pTmp^.mkid.cb :=uSize;
pTmp :=GetNextItem(pTmp);
pTmp^.mkid.cb :=0;
pTmp^.mkid.abID[0] :=0;
end;
Result :=pidl

end;
居然出错,系统报内存不可写,但SHGetMalloc在普通模式下(即;随便建一个工程,应用IMalloc分配内存)又是正常的,下面C++的代码:
class CPidlMgr
{
public:
CPidlMgr();
~CPidlMgr();
.......................
CPidlMgr::CPidlMgr()
{
//get the shell's IMalloc pointer
//we'll keep this until we get destroyed
if(FAILED(SHGetMalloc(&amp;m_pMalloc)))
{
delete this;
}

g_DllRefCount++;
}
LPITEMIDLIST CPidlMgr::Create(PIDLTYPE type, LPVOID pIn, USHORT uInSize)
{
LPITEMIDLIST pidlOut;
USHORT uSize;

pidlOut = NULL;

/*
Calculate the size. This consists of the ITEMIDLIST, the PIDL structure plus
the size of the data. We subtract the size of an HKEY because that is included
in uInSize.
*/
uSize = sizeof(ITEMIDLIST) + (sizeof(PIDLDATA) - sizeof(HKEY)) + uInSize;

/*
Allocate the memory, adding an additional ITEMIDLIST for the NULL terminating
ID List.
*/
pidlOut = (LPITEMIDLIST)m_pMalloc->Alloc(uSize + sizeof(ITEMIDLIST));
...........,
在C++中是正常的,有谁知道怎么在空间命名扩展中(即:IEnumIDList里)应用IMalloc分配内存
 
即在空间命名扩展应用中,要为PIDL分配内存,SHGetMalloc函数居然出现异常,
constructor TPidlMgr.Create
//初始化
begin
inherited Create;
FMalloc :=nil;
SHGetMalloc(FMalloc);
end;

function TPidlMgr.CreateIDLits: PITEMIDLIST;
var
pidl,pTmp:PITEMIDLIST;
uSize:WORD;
begin
uSize :=sizeof(ITEMIDLIST)+4;
pidl :=FMalloc.Alloc(uSize+sizeof(ITEMIDLIST))
//居然出错,系统报内存不可写
if pidl<>nil then
begin
pTmp :=pidl;
pTmp^.mkid.cb :=uSize;
pTmp :=GetNextItem(pTmp);
pTmp^.mkid.cb :=0;
pTmp^.mkid.abID[0] :=0;
end;
Result :=pidl

end;
居然出错,系统报内存不可写,但SHGetMalloc在普通模式下(即;随便建一个工程,应用IMalloc分配内存)又是正常的,下面C++的代码:
class CPidlMgr
{
public:
CPidlMgr();
~CPidlMgr();
.......................
CPidlMgr::CPidlMgr()
{
//get the shell's IMalloc pointer
//we'll keep this until we get destroyed
if(FAILED(SHGetMalloc(&amp;m_pMalloc)))
{
delete this;
}

g_DllRefCount++;
}
LPITEMIDLIST CPidlMgr::Create(PIDLTYPE type, LPVOID pIn, USHORT uInSize)
{
LPITEMIDLIST pidlOut;
USHORT uSize;

pidlOut = NULL;

/*
Calculate the size. This consists of the ITEMIDLIST, the PIDL structure plus
the size of the data. We subtract the size of an HKEY because that is included
in uInSize.
*/
uSize = sizeof(ITEMIDLIST) + (sizeof(PIDLDATA) - sizeof(HKEY)) + uInSize;

/*
Allocate the memory, adding an additional ITEMIDLIST for the NULL terminating
ID List.
*/
pidlOut = (LPITEMIDLIST)m_pMalloc->Alloc(uSize + sizeof(ITEMIDLIST));
...........,
在C++中是正常的,有谁知道怎么在空间命名扩展中(即:IEnumIDList里)应用IMalloc分配内存
 
后退
顶部