int main(int, char *[]) { HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) { int iArgs = 0; PWSTR *ppszArgs = CommandLineToArgvW(GetCommandLineW(), &iArgs); KNOWNFOLDERID kfid = GUID_NULL; KNOWNFOLDER_DEFINITION kfd = {}; ACTION_TYPE at; PWSTR pszFindForPath = NULL; if (ParseAndValidateCommandLine(ppszArgs, iArgs, &at, &kfid, &kfd, &pszFindForPath)) { switch (at) { case ACT_REGISTER: { if (GUID_NULL == kfid) { CoCreateGuid(&kfid); } CompleteKnownFolderDef(&kfd); hr = RegisterKnownFolder(kfid, &kfd); if (S_OK == hr) { // we create our knownfolder with SHGetKnownFolderPath() so that the shell will write // the desktop.ini file in the folder. This is how our customizations // (i.e.: pszIcon, pszTooltip and pszLocalizedName) get picked up by explorer. PWSTR pszPath = NULL; hr = SHGetKnownFolderPath(kfid, KF_FLAG_CREATE | KF_FLAG_INIT, NULL, &pszPath); if (S_OK != hr) { wprintf(L"SHGetKnownFolderPath(KF_FLAG_CREATE | KF_FLAG_INIT) returned hr=0x%x\nThe KnownFolder was not registered.\n", hr); hr = UnregisterFolder(kfid); if (S_OK != hr) { wprintf(L"IKnownFolderManager::UnregisterFolder returned hr=0x%x.\nThe folder was NOT unregistered.\n", hr); } else { wprintf(L"The KnownFolder was not registered.\n"); } } else { CoTaskMemFree(pszPath); DumpKnownFolderDef(kfid, kfd); } } } break; case ACT_ENUM: wprintf(L"Enumerating all registered KnownFolders \n"); if (kfd.pszName) { wprintf(L" matching pszName '%s'...\n", kfd.pszName); } else if (GUID_NULL != kfid) { WCHAR szGuid[GUID_SIZE]; StringFromGUID2(kfid, szGuid, ARRAYSIZE(szGuid)); wprintf(L" matching KNOWNFOLDERID %s...\n", szGuid); } DWORD dwCKF; EnumAndDumpKnownFolders(&dwCKF, kfd.pszName, kfid); wprintf(L"Finished enumerating %d registered KnownFolders enumerated.\n", dwCKF); break; case ACT_UNREGISTER: if (GUID_NULL == kfid) { DumpUsage(); } else { hr = UnregisterFolder(kfid); if (S_OK != hr) { wprintf(L"IKnownFolderManager::UnregisterFolder returned hr=0x%x\n", hr); } } break; case ACT_CLEAN: wprintf(L"Unregistering all KnownFolders registered by this tool\n"); DWORD dw; UnregisterAllKFsAddedByThisTool(&dw); wprintf(L"Unregistered %d KnownFolders\n", dw); break; case ACT_FIND_FOR_PATH: hr = GetKnownFolderForPath(pszFindForPath, &kfid, &kfd); if (SUCCEEDED(hr)) { DumpKnownFolderDef(kfid, kfd); } else { wprintf(L"Failed to find KnownFolder for path: %s\n", pszFindForPath); } break; case ACT_SHOW_USAGE: default: DumpUsage(); break; } FreeKnownFolderDefinitionFields(&kfd); CoTaskMemFree(pszFindForPath); } else { DumpUsage(); } CoUninitialize(); } return 0; }
xHeap::~xHeap() { #if defined(_DEBUG) || defined(DEBUG_APP_HEAP_DUMP_LEAK_ON_EXIT) const char * dumpFilename = "dump-err-exit.log"; if(smallStats.allocCount != smallStats.freeCount #ifndef USE_APP_HEAP_SAVING_MODE || mediumStats.allocCount != mediumStats.freeCount #endif // USE_APP_HEAP_SAVING_MODE || largeStats.allocCount != largeStats.freeCount ) { DumpUsage(dumpFilename); } else { // IFILEMGR_Remove(fileMgr, dumpFilename); } #endif #ifdef _MSC_VER ASSERT("Memory leak found!" && smallStats.allocCount == smallStats.freeCount); #ifndef USE_APP_HEAP_SAVING_MODE ASSERT("Memory leak found!" && mediumStats.allocCount == mediumStats.freeCount); #endif // USE_APP_HEAP_SAVING_MODE ASSERT("Memory leak found!" && largeStats.allocCount == largeStats.freeCount); #endif // _MSC_VER // if(smallStats.allocCount == smallStats.freeCount) { while(smallPage != &dummySmallPage) { SmallPage * curPage = smallPage; smallPage = smallPage->next; FREE(curPage); } } // if(largeStats.allocCount == largeStats.freeCount) { while(dummyLargeBlock.next != &dummyLargeBlock) { void * p = (char*)(dummyLargeBlock.next+1) + DUMMY_ID_SIZE/2; Free(p); } } #ifndef USE_APP_HEAP_SAVING_MODE // if(mediumStats.allocCount == mediumStats.freeCount) { for(Block * block = dummyBlock.next, * next; block != &dummyBlock; block = next) { next = block->next; if(!block->isFree) { void * p = (char*)(block+1) + DUMMY_ID_SIZE/2; Free(p); } } while(dummyBlock.next != &dummyBlock) { Block * curBlockPage = dummyBlock.next; curBlockPage->RemoveLink(); #ifdef _MSC_VER ASSERT("Heap corrupted!" && curBlockPage->page != curBlockPage->next->page); ASSERT("Heap corrupted!" && curBlockPage->page != curBlockPage->prev->page); #endif // _MSC_VER FREE(curBlockPage); } } #endif // USE_APP_HEAP_SAVING_MODE if(instance == this) { *((xHeap**)(&instance)) = NULL; } }