我有一个 ActiveX,它向服务器询问 URL 并下载/读取数据并要求新的数据缓冲区直到完成。数据被正确读取,但如果我观察任务管理器,IE 的内存和句柄会上升,而且永远不会下降。进程资源管理器显示句柄是缓存文件。
int AXGetUrl(char* url,
void* buffer,
int buffer_size,
void* pUnk)
{
char buffer2[256];
int rc;
HRESULT rc2;
ULONG buffer_len;
ULONG buffer_len2;
IStream* pStream;
char newurl[1024];
ULONG64 RequestBytes;
CURLCallBack UCB;
//Initialize
rc = 0;
rc2 = 0;
memset(newurl,
0x00,
sizeof(newurl));
buffer_len = 0;
pStream = NULL;
RequestBytes = 0;
strcpy(newurl,
url);
rc = URLOpenBlockingStream((IUnknown *)pUnk,
url,
&pStream,
0,
&UCB);
while (rc == 0)
{
if (pStream != NULL)
{
rc2 = pStream->Read(buffer,
buffer_size,
&buffer_len);
RequestBytes = RequestBytes + buffer_len;
pStream->Release();
pStream = NULL;
buildnewurl(newurl,
RequestBytes);
rc = URLOpenBlockingStream((IUnknown *)pUnk,
newurl,
&pStream,
0,
&UCB);
}
else
{
rc = 1;
}
}
return (rc);
}
更新:
#include "stdafx.h"
#include "Test.h"
Test::Test()
{
}
Test::~Test()
{
}
HRESULT Test::FinalConstruct()
{
void* pUnk = NULL;
void* buffer = NULL;
int buffer_size = 131072;
ULONG buffer_len = 0;
HRESULT rc = 0;
HRESULT rc2 = 0;
IStream* pStream = NULL;
int counter = 0;
char url[1024];
rc = QueryInterface(IID_IUnknown, &pUnk);
buffer = malloc(buffer_size);
if (buffer != NULL)
{
//Get URL
sprintf(url,
"http://search.yahoo.com/search?p=%d",
counter);
rc = URLOpenBlockingStream((IUnknown *)pUnk,
url,
&pStream,
0,
NULL);
while (rc == 0)
{
if (pStream != NULL)
{
rc2 = pStream->Read(buffer,
buffer_size,
&buffer_len);
pStream->Release();
pStream = NULL;
counter++;
if (counter == 15)
{
break;
}
sprintf(url,
"http://search.yahoo.com/search?p=%d",
counter);
rc = URLOpenBlockingStream((IUnknown *)pUnk,
url,
&pStream,
0,
NULL);
}
else
{
rc = 1;
}
}
free(buffer);
}
return (S_OK);
}
void Test::FinalRelease()
{
return;
}