问题描述
你好,
我使用WTL 8库,发现其中一个标头(atldlgs.h)存在问题,该标头使用GlobalReAlloc函数.
基本上,该函数失败,返回NULL指针,而GetLastError()返回8,这意味着内存不足".当然,我有足够的可用内存...并且请求的字节数非常低.
有人知道GlobalReAlloc失败的原因吗?这是一些错误吗?
还是我错过了什么?
在此先感谢您提供任何有关此信息,
奥利维尔.
我正在使用Windows Vista SP2 + VS2008.
这是一个重现该错误的简单程序:
stdafx.h :
Hello,
I''im using the WTL 8 library, and I found there''s a problem in one of the headers (atldlgs.h), which makes use of the GlobalReAlloc function.
Basically, the function fails, returns a NULL pointer, and GetLastError() returns 8, which means "not enough memory". Of course I have plenty of memory available... and the amount of requested bytes is very low.
Does some know the reason why GlobalReAlloc would fail? is it some bug ?
Or did I miss something?
Thanks in advance for any information about this,
Olivier.
I''m using Windows Vista SP2 + VS 2008.
Here is a simple program to reproduce the error:
stdafx.h:
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <conio.h>
testGlobalReAlloc.cpp :
testGlobalReAlloc.cpp:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
int size1 = 10240;
int size2 = 20480;
for (int i=0; i<15; i++)
{
HGLOBAL h = ::GlobalAlloc(GPTR, size1);
if (NULL == h)
{
_tprintf(_T("NULL! %d\r\n"), i);
break;
}
HGLOBAL h2 = ::GlobalReAlloc(h, size2, 0);
if (NULL == h2)
{
::GlobalFree(h);
_tprintf(_T("NULL 2! %d\r\n"), i); // gets here the first time GlobalReAlloc is used
break;
}
::GlobalFree(h2);
_tprintf(_T("ok %d\r\n"), i);
}
_tprintf(_T("press key\r\n"));
getch();
return 0;
}
推荐答案
这篇关于GlobalReAlloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!