static void test_IMalloc(void) { LPVOID lpMem; ULONG ulRef; int iRet; HRESULT hRet; LPMALLOC lpMalloc; LPVOID lpVoid; pMAPIGetDefaultMalloc = (void*)GetProcAddress(hMapi32, "MAPIGetDefaultMalloc@0"); if (!pMAPIGetDefaultMalloc) { win_skip("MAPIGetDefaultMalloc is not available\n"); return; } lpMalloc = pMAPIGetDefaultMalloc(); ok(lpMalloc != NULL, "Expected MAPIGetDefaultMalloc to return non-NULL\n"); if (!lpMalloc) { skip("MAPIGetDefaultMalloc failed\n"); return; } lpVoid = NULL; hRet = IMalloc_QueryInterface(lpMalloc, &IID_IUnknown, &lpVoid); ok (hRet == S_OK && lpVoid != NULL, "IID_IUnknown: expected S_OK, non-null, got 0x%08x, %p\n", hRet, lpVoid); lpVoid = NULL; hRet = IMalloc_QueryInterface(lpMalloc, &IID_IMalloc, &lpVoid); ok (hRet == S_OK && lpVoid != NULL, "IID_IIMalloc: expected S_OK, non-null, got 0x%08x, %p\n", hRet, lpVoid); /* Prove that native mapi uses LocalAlloc/LocalFree */ lpMem = IMalloc_Alloc(lpMalloc, 61); ok (lpMem && IMalloc_GetSize(lpMalloc, lpMem) == LocalSize(lpMem), "Expected non-null, same size, got %p, %s size\n", lpMem, lpMem ? "different" : "same"); iRet = IMalloc_DidAlloc(lpMalloc, lpMem); ok (iRet == -1, "DidAlloc, expected -1. got %d\n", iRet); IMalloc_HeapMinimize(lpMalloc); LocalFree(lpMem); ulRef = IMalloc_AddRef(lpMalloc); ok (ulRef == 1u, "AddRef expected 1, returned %d\n", ulRef); ulRef = IMalloc_Release(lpMalloc); ok (ulRef == 1u, "AddRef expected 1, returned %d\n", ulRef); IMalloc_Release(lpMalloc); }
int folder_dialog(HWND hwnd, char *path) { BROWSEINFO BINFO; LPITEMIDLIST pidl; LPMALLOC pMalloc; int res = 0; if (SUCCEEDED(SHGetMalloc(&pMalloc))) { memset(&BINFO, 0, sizeof(BINFO)); BINFO.hwndOwner = hwnd; #ifdef CHINESE BINFO.lpszTitle = "选择ROM文件夹"; #else BINFO.lpszTitle = "Select ROM folder"; #endif BINFO.ulFlags = BIF_RETURNONLYFSDIRS; pidl = SHBrowseForFolder(&BINFO); if (pidl) { res = SHGetPathFromIDList(pidl, path); IMalloc_Free(pMalloc, pidl); } IMalloc_Release(pMalloc); } return res; }
static ULONG WINAPI xmlwriter_Release(IXmlWriter *iface) { xmlwriter *This = impl_from_IXmlWriter(iface); LONG ref; TRACE("%p\n", This); ref = InterlockedDecrement(&This->ref); if (ref == 0) { struct element *element, *element2; IMalloc *imalloc = This->imalloc; IXmlWriter_Flush(iface); if (This->output) IUnknown_Release(&This->output->IXmlWriterOutput_iface); /* element stack */ LIST_FOR_EACH_ENTRY_SAFE(element, element2, &This->elements, struct element, entry) { list_remove(&element->entry); free_element(This, element); } writer_free(This, This); if (imalloc) IMalloc_Release(imalloc); } return ref; }
static NTSTATUS EnumRunningObjectTable( _In_ PVOID ThreadParam ) { IRunningObjectTable* iRunningObjectTable = NULL; IEnumMoniker* iEnumMoniker = NULL; IMoniker* iMoniker = NULL; IBindCtx* iBindCtx = NULL; IMalloc* iMalloc = NULL; ULONG count = 0; HWND listViewHandle = (HWND)ThreadParam; if (!SUCCEEDED(CoGetMalloc(1, &iMalloc))) return STATUS_INSUFFICIENT_RESOURCES; // Query the running object table address if (SUCCEEDED(GetRunningObjectTable(0, &iRunningObjectTable))) { // Enum the objects registered if (SUCCEEDED(IRunningObjectTable_EnumRunning(iRunningObjectTable, &iEnumMoniker))) { while (IEnumMoniker_Next(iEnumMoniker, 1, &iMoniker, &count) == S_OK) { if (SUCCEEDED(CreateBindCtx(0, &iBindCtx))) { OLECHAR* displayName = NULL; // Query the object name if (SUCCEEDED(IMoniker_GetDisplayName(iMoniker, iBindCtx, NULL, &displayName))) { // Set the items name column PhAddListViewItem(listViewHandle, MAXINT, displayName, NULL); // Free the object name IMalloc_Free(iMalloc, displayName); } IBindCtx_Release(iBindCtx); } IEnumMoniker_Release(iMoniker); } IEnumMoniker_Release(iEnumMoniker); } IRunningObjectTable_Release(iRunningObjectTable); } IMalloc_Release(iMalloc); return STATUS_SUCCESS; }
static ULONG WINAPI xmlwriteroutput_Release(IXmlWriterOutput *iface) { xmlwriteroutput *This = impl_from_IXmlWriterOutput(iface); LONG ref = InterlockedDecrement(&This->ref); TRACE("(%p)->(%d)\n", This, ref); if (ref == 0) { IMalloc *imalloc = This->imalloc; if (This->output) IUnknown_Release(This->output); if (This->stream) ISequentialStream_Release(This->stream); free_output_buffer(This); writeroutput_free(This, This); if (imalloc) IMalloc_Release(imalloc); } return ref; }
static ULONG WINAPI xmlwriter_Release(IXmlWriter *iface) { xmlwriter *This = impl_from_IXmlWriter(iface); LONG ref; TRACE("%p\n", This); ref = InterlockedDecrement(&This->ref); if (ref == 0) { IMalloc *imalloc = This->imalloc; IXmlWriter_Flush(iface); if (This->output) IUnknown_Release(&This->output->IXmlWriterOutput_iface); writer_free(This, This); if (imalloc) IMalloc_Release(imalloc); } return ref; }
BOOL BrowseForDirectory(HWND hwnd, LPCTSTR pStartDir, TCHAR* pResult) { BOOL bResult = FALSE; IMalloc* piMalloc = 0; BROWSEINFO Info; LPITEMIDLIST pItemIDList = NULL; TCHAR buf[MAX_PATH]; if (!SUCCEEDED(SHGetMalloc(&piMalloc))) return FALSE; Info.hwndOwner = hwnd; Info.pidlRoot = NULL; Info.pszDisplayName = buf; Info.lpszTitle = TEXT("Directory name:"); Info.ulFlags = BIF_RETURNONLYFSDIRS; Info.lpfn = BrowseCallbackProc; Info.lParam = (LPARAM)pStartDir; pItemIDList = SHBrowseForFolder(&Info); if (pItemIDList != NULL) { if (SHGetPathFromIDList(pItemIDList, buf) == TRUE) { _sntprintf(pResult, MAX_PATH, TEXT("%s"), buf); bResult = TRUE; } IMalloc_Free(piMalloc, pItemIDList); } else { bResult = FALSE; } IMalloc_Release(piMalloc); return bResult; }
BOOL BrowseForDirectory(HWND hwnd, const char* pStartDir, char* pResult) { BOOL bResult = FALSE; IMalloc* piMalloc = 0; BROWSEINFO Info; ITEMIDLIST* pItemIDList = NULL; char buf[MAX_PATH]; if (!SUCCEEDED(SHGetMalloc(&piMalloc))) return FALSE; Info.hwndOwner = hwnd; Info.pidlRoot = NULL; Info.pszDisplayName = buf; Info.lpszTitle = (LPCSTR)"Directory name:"; Info.ulFlags = BIF_RETURNONLYFSDIRS; Info.lpfn = BrowseCallbackProc; Info.lParam = (LPARAM)pStartDir; pItemIDList = SHBrowseForFolder(&Info); if (pItemIDList != NULL) { if (SHGetPathFromIDList(pItemIDList, buf) == TRUE) { strncpy(pResult, buf, MAX_PATH); bResult = TRUE; } IMalloc_Free(piMalloc, pItemIDList); } else { bResult = FALSE; } IMalloc_Release(piMalloc); return bResult; }