hhctrl.ocx: Handle memory allocation in OpenCHM and CloseCHM.
This commit is contained in:
parent
976f2db58d
commit
1711c3a5c4
|
@ -127,48 +127,60 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Opens the CHM file for reading */
|
/* Opens the CHM file for reading */
|
||||||
BOOL CHM_OpenCHM(CHMInfo *pChmInfo, LPCWSTR szFile)
|
CHMInfo *OpenCHM(LPCWSTR szFile)
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
static const WCHAR wszSTRINGS[] = {'#','S','T','R','I','N','G','S',0};
|
static const WCHAR wszSTRINGS[] = {'#','S','T','R','I','N','G','S',0};
|
||||||
|
|
||||||
pChmInfo->szFile = szFile;
|
CHMInfo *ret = hhctrl_alloc_zero(sizeof(CHMInfo));
|
||||||
|
|
||||||
if (FAILED(CoCreateInstance(&CLSID_ITStorage, NULL, CLSCTX_INPROC_SERVER,
|
ret->szFile = szFile;
|
||||||
&IID_IITStorage, (void **) &pChmInfo->pITStorage)))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (FAILED(IITStorage_StgOpenStorage(pChmInfo->pITStorage, szFile, NULL,
|
hres = CoCreateInstance(&CLSID_ITStorage, NULL, CLSCTX_INPROC_SERVER,
|
||||||
STGM_READ | STGM_SHARE_DENY_WRITE,
|
&IID_IITStorage, (void **) &ret->pITStorage) ;
|
||||||
NULL, 0, &pChmInfo->pStorage)))
|
if(FAILED(hres)) {
|
||||||
return FALSE;
|
WARN("Could not create ITStorage: %08x\n", hres);
|
||||||
|
return CloseCHM(ret);
|
||||||
|
}
|
||||||
|
|
||||||
hres = IStorage_OpenStream(pChmInfo->pStorage, wszSTRINGS, NULL, STGM_READ, 0,
|
hres = IITStorage_StgOpenStorage(ret->pITStorage, szFile, NULL,
|
||||||
&pChmInfo->strings_stream);
|
STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &ret->pStorage);
|
||||||
|
if(FAILED(hres)) {
|
||||||
|
WARN("Could not open storage: %08x\n", hres);
|
||||||
|
return CloseCHM(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
hres = IStorage_OpenStream(ret->pStorage, wszSTRINGS, NULL, STGM_READ, 0,
|
||||||
|
&ret->strings_stream);
|
||||||
if(FAILED(hres)) {
|
if(FAILED(hres)) {
|
||||||
WARN("Could not open #STRINGS stream: %08x\n", hres);
|
WARN("Could not open #STRINGS stream: %08x\n", hres);
|
||||||
return FALSE;
|
return CloseCHM(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
pChmInfo->strings = NULL;
|
return ret;
|
||||||
pChmInfo->strings_size = 0;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHM_CloseCHM(CHMInfo *pCHMInfo)
|
CHMInfo *CloseCHM(CHMInfo *chm)
|
||||||
{
|
{
|
||||||
IITStorage_Release(pCHMInfo->pITStorage);
|
if(chm->pITStorage)
|
||||||
IStorage_Release(pCHMInfo->pStorage);
|
IITStorage_Release(chm->pITStorage);
|
||||||
IStream_Release(pCHMInfo->strings_stream);
|
|
||||||
|
|
||||||
if(pCHMInfo->strings_size) {
|
if(chm->pStorage)
|
||||||
|
IStorage_Release(chm->pStorage);
|
||||||
|
|
||||||
|
if(chm->strings_stream)
|
||||||
|
IStream_Release(chm->strings_stream);
|
||||||
|
|
||||||
|
if(chm->strings_size) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i=0; i<pCHMInfo->strings_size; i++)
|
for(i=0; i<chm->strings_size; i++)
|
||||||
hhctrl_free(pCHMInfo->strings[i]);
|
hhctrl_free(chm->strings[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
hhctrl_free(pCHMInfo->strings);
|
hhctrl_free(chm->strings);
|
||||||
|
hhctrl_free(chm);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -800,10 +800,7 @@ static void HH_Close(HHInfo *pHHInfo)
|
||||||
hhctrl_free(pHHInfo->pHHWinType);
|
hhctrl_free(pHHInfo->pHHWinType);
|
||||||
|
|
||||||
if (pHHInfo->pCHMInfo)
|
if (pHHInfo->pCHMInfo)
|
||||||
{
|
CloseCHM(pHHInfo->pCHMInfo);
|
||||||
CHM_CloseCHM(pHHInfo->pCHMInfo);
|
|
||||||
hhctrl_free(pHHInfo->pCHMInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pHHInfo->pWBInfo)
|
if (pHHInfo->pWBInfo)
|
||||||
{
|
{
|
||||||
|
@ -816,12 +813,16 @@ static HHInfo *HH_OpenHH(LPWSTR filename)
|
||||||
{
|
{
|
||||||
HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
|
HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
|
||||||
|
|
||||||
|
pHHInfo->pCHMInfo = OpenCHM(filename);
|
||||||
|
if(!pHHInfo->pCHMInfo) {
|
||||||
|
HH_Close(pHHInfo);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pHHInfo->pHHWinType = hhctrl_alloc_zero(sizeof(HH_WINTYPEW));
|
pHHInfo->pHHWinType = hhctrl_alloc_zero(sizeof(HH_WINTYPEW));
|
||||||
pHHInfo->pCHMInfo = hhctrl_alloc(sizeof(CHMInfo));
|
|
||||||
pHHInfo->pWBInfo = hhctrl_alloc(sizeof(WBInfo));
|
pHHInfo->pWBInfo = hhctrl_alloc(sizeof(WBInfo));
|
||||||
|
|
||||||
if (!CHM_OpenCHM(pHHInfo->pCHMInfo, filename)
|
if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType)) {
|
||||||
|| !CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType)) {
|
|
||||||
HH_Close(pHHInfo);
|
HH_Close(pHHInfo);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,9 +70,9 @@ void WB_UnEmbedBrowser(WBInfo *pWBInfo);
|
||||||
void WB_ResizeBrowser(WBInfo *pWBInfo, DWORD dwWidth, DWORD dwHeight);
|
void WB_ResizeBrowser(WBInfo *pWBInfo, DWORD dwWidth, DWORD dwHeight);
|
||||||
void WB_DoPageAction(WBInfo *pWBInfo, DWORD dwAction);
|
void WB_DoPageAction(WBInfo *pWBInfo, DWORD dwAction);
|
||||||
|
|
||||||
BOOL CHM_OpenCHM(CHMInfo *pCHMInfo, LPCWSTR szFile);
|
CHMInfo *OpenCHM(LPCWSTR szFile);
|
||||||
BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
|
BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
|
||||||
void CHM_CloseCHM(CHMInfo *pCHMInfo);
|
CHMInfo *CloseCHM(CHMInfo *pCHMInfo);
|
||||||
|
|
||||||
/* memory allocation functions */
|
/* memory allocation functions */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue