/******************************************************************** WcaGetRecordFormattedString() - gets formatted string filed from record ********************************************************************/ extern "C" HRESULT WIXAPI WcaGetRecordFormattedString( __in MSIHANDLE hRec, __in UINT uiField, __inout LPWSTR* ppwzData ) { if (!hRec || !ppwzData) { return E_INVALIDARG; } HRESULT hr = S_OK; UINT er; DWORD_PTR cch = 0; PMSIHANDLE hRecFormat; // get the format string hr = WcaGetRecordString(hRec, uiField, ppwzData); ExitOnFailure(hr, "failed to get string from record"); if (!**ppwzData) { ExitFunction(); } // hide the nulls '[~]' so we can get them back after formatting HideNulls(*ppwzData); // set up the format record hRecFormat = ::MsiCreateRecord(1); ExitOnNull(hRecFormat, hr, E_UNEXPECTED, "Failed to create record to format string"); hr = WcaSetRecordString(hRecFormat, 0, *ppwzData); ExitOnFailure(hr, "failed to set string to format record"); // format the string hr = StrMaxLength(*ppwzData, &cch); ExitOnFailure(hr, "failed to get max length of string"); er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch); if (ERROR_MORE_DATA == er) { hr = StrAlloc(ppwzData, ++cch); ExitOnFailure(hr, "Failed to allocate memory for record string"); er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch); } ExitOnWin32Error(er, hr, "Failed to format string"); // put the nulls back RevealNulls(*ppwzData); LExit: return hr; }
extern "C" HRESULT WINAPI UpdateThreadCheck( __in LPCWSTR wzAppId, __in BOOL fTryExecuteUpdate ) { HRESULT hr = S_OK; BOOL fLocked = FALSE; BACKGROUND_UPDATE_THREAD_CONTEXT* pContext = NULL; ::EnterCriticalSection(&vUpdateThreadLock); fLocked = TRUE; if (vhUpdateThread) { DWORD er = ::WaitForSingleObject(vhUpdateThread, 0); if (WAIT_OBJECT_0 == er) { ::CloseHandle(vhUpdateThread); vhUpdateThread = NULL; } else { hr = S_FALSE; ExitFunction(); } } pContext = static_cast<BACKGROUND_UPDATE_THREAD_CONTEXT*>(MemAlloc(sizeof(BACKGROUND_UPDATE_THREAD_CONTEXT), TRUE)); ExitOnNull(pContext, hr, E_OUTOFMEMORY, "Failed to allocate memory for context."); hr= StrAllocString(&pContext->pwzApplicationId, wzAppId, 0); ExitOnFailure(hr, "Failed to copy app id into context."); pContext->fExecuteUpdate = fTryExecuteUpdate; vhUpdateThread = ::CreateThread(NULL, 0, BackgroundUpdateThread, reinterpret_cast<LPVOID>(pContext), 0, NULL); ExitOnNullWithLastError(vhUpdateThread, hr, "Failed to create background update thread."); pContext = NULL; LExit: if (pContext) { ReleaseStr(pContext->pwzApplicationId); MemFree(pContext); } if (fLocked) { ::LeaveCriticalSection(&vUpdateThreadLock); } return hr; }
HRESULT CpiGetCatalogCollection( ICatalogCollection* piColl, ICatalogObject* piObj, LPCWSTR pwzName, ICatalogCollection** ppiColl ) { HRESULT hr = S_OK; ICOMAdminCatalog* piCatalog = NULL; IDispatch* piDisp = NULL; BSTR bstrName = NULL; VARIANT vtKey; ::VariantInit(&vtKey); // copy name string bstrName = ::SysAllocString(pwzName); ExitOnNull(bstrName, hr, E_OUTOFMEMORY, "Failed to allocate BSTR for collection name"); // get catalog hr = CpiGetAdminCatalog(&piCatalog); ExitOnFailure(hr, "Failed to get COM+ admin catalog"); // get key hr = piObj->get_Key(&vtKey); ExitOnFailure(hr, "Failed to get object key"); // get collecton from catalog hr = piColl->GetCollection(bstrName, vtKey, &piDisp); ExitOnFailure(hr, "Failed to get collection"); hr = piDisp->QueryInterface(IID_ICatalogCollection, (void**)ppiColl); ExitOnFailure(hr, "Failed to get IID_ICatalogCollection interface"); // populate collection hr = (*ppiColl)->Populate(); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to populate collection"); hr = S_OK; LExit: // clean up ReleaseObject(piCatalog); ReleaseObject(piDisp); ReleaseBSTR(bstrName); ::VariantClear(&vtKey); return hr; }
// private helper functions static HRESULT AddFilterToList(SCA_FILTER** ppsfList) { HRESULT hr = S_OK; SCA_FILTER* psf = (SCA_FILTER*)MemAlloc(sizeof(SCA_FILTER), TRUE); ExitOnNull(psf, hr, E_OUTOFMEMORY, "failed to add filter to filter list"); psf->psfNext = *ppsfList; *ppsfList = psf; LExit: return hr; }
HRESULT MqiInitialize() { HRESULT hr = S_OK; // load mqrt.dll ghMQRT = ::LoadLibraryW(L"mqrt.dll"); ExitOnNull(ghMQRT, hr, E_FAIL, "Failed to load mqrt.dll"); // get MQCreateQueue function address gpfnMQCreateQueue = (MQCreateQueueFunc)::GetProcAddress(ghMQRT, "MQCreateQueue"); ExitOnNull(gpfnMQCreateQueue, hr, HRESULT_FROM_WIN32(::GetLastError()), "Failed get address for MQCreateQueue() function"); // get MQDeleteQueue function address gpfnMQDeleteQueue = (MQDeleteQueueFunc)::GetProcAddress(ghMQRT, "MQDeleteQueue"); ExitOnNull(gpfnMQDeleteQueue, hr, HRESULT_FROM_WIN32(::GetLastError()), "Failed get address for MQDeleteQueue() function"); // get MQPathNameToFormatName function address gpfnMQPathNameToFormatName = (MQPathNameToFormatNameFunc)::GetProcAddress(ghMQRT, "MQPathNameToFormatName"); ExitOnNull(gpfnMQPathNameToFormatName, hr, HRESULT_FROM_WIN32(::GetLastError()), "Failed get address for MQPathNameToFormatName() function"); // get MQGetQueueSecurity function address gpfnMQGetQueueSecurity = (MQGetQueueSecurityFunc)::GetProcAddress(ghMQRT, "MQGetQueueSecurity"); ExitOnNull(gpfnMQGetQueueSecurity, hr, HRESULT_FROM_WIN32(::GetLastError()), "Failed get address for MQGetQueueSecurity() function"); // get MQSetQueueSecurity function address gpfnMQSetQueueSecurity = (MQSetQueueSecurityFunc)::GetProcAddress(ghMQRT, "MQSetQueueSecurity"); ExitOnNull(gpfnMQSetQueueSecurity, hr, HRESULT_FROM_WIN32(::GetLastError()), "Failed get address for MQSetQueueSecurity() function"); hr = S_OK; LExit: return hr; }
static HRESULT AddWebErrorToList(SCA_WEB_ERROR** ppsweList) { HRESULT hr = S_OK; SCA_WEB_ERROR* pswe = static_cast<SCA_WEB_ERROR*>(MemAlloc(sizeof(SCA_WEB_ERROR), TRUE)); ExitOnNull(pswe, hr, E_OUTOFMEMORY, "failed to allocate memory for new web error list element"); pswe->psweNext = *ppsweList; *ppsweList = pswe; LExit: return hr; }
static HRESULT NewSqlStr( __out SCA_SQLSTR** ppsss ) { HRESULT hr = S_OK; SCA_SQLSTR* psss = static_cast<SCA_SQLSTR*>(MemAlloc(sizeof(SCA_SQLSTR), TRUE)); ExitOnNull(psss, hr, E_OUTOFMEMORY, "failed to allocate memory for new sql string element"); *ppsss = psss; LExit: return hr; }
static HRESULT NewDb( __out SCA_DB** ppsd ) { HRESULT hr = S_OK; SCA_DB* psd = static_cast<SCA_DB*>(MemAlloc(sizeof(SCA_DB), TRUE)); ExitOnNull(psd, hr, E_OUTOFMEMORY, "failed to allocate memory for new database element"); *ppsd = psd; LExit: return hr; }
static HRESULT AddMimeMapToList(SCA_MIMEMAP** ppsmmList) { HRESULT hr = S_OK; SCA_MIMEMAP* psmm = static_cast<SCA_MIMEMAP*>(MemAlloc(sizeof(SCA_MIMEMAP), TRUE)); ExitOnNull(psmm, hr, E_OUTOFMEMORY, "failed to allocate memory for new mime map list element"); psmm->psmmNext = *ppsmmList; *ppsmmList = psmm; LExit: return hr; }
static HRESULT NewAppExt( SCA_WEB_APPLICATION_EXTENSION** ppswappext ) { HRESULT hr = S_OK; SCA_WEB_APPLICATION_EXTENSION* pswappext = (SCA_WEB_APPLICATION_EXTENSION*)MemAlloc(sizeof(SCA_WEB_APPLICATION_EXTENSION), TRUE); ExitOnNull(pswappext, hr, E_OUTOFMEMORY, "failed to allocate memory for new web app ext element"); *ppswappext = pswappext; LExit: return hr; }
static HRESULT ParseWxlControls( __in IXMLDOMElement* pElement, __in WIX_LOCALIZATION* pWixLoc ) { HRESULT hr = S_OK; IXMLDOMNode* pixn = NULL; IXMLDOMNodeList* pixnl = NULL; DWORD dwIdx = 0; hr = XmlSelectNodes(pElement, L"UI|Control", &pixnl); ExitOnLastError(hr, "Failed to get UI child nodes of Wxl File."); hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocControls)); ExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File."); if (0 < pWixLoc->cLocControls) { pWixLoc->rgLocControls = static_cast<LOC_CONTROL*>(MemAlloc(sizeof(LOC_CONTROL) * pWixLoc->cLocControls, TRUE)); ExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls."); while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) { hr = ParseWxlControl(pixn, dwIdx, pWixLoc); ExitOnFailure(hr, "Failed to parse localized control."); ++dwIdx; ReleaseNullObject(pixn); } hr = S_OK; ExitOnFailure(hr, "Failed to enumerate all localized controls."); } LExit: if (FAILED(hr) && pWixLoc->rgLocControls) { for (DWORD idx = 0; idx < pWixLoc->cLocControls; ++idx) { ReleaseStr(pWixLoc->rgLocControls[idx].wzControl); ReleaseStr(pWixLoc->rgLocControls[idx].wzText); } ReleaseMem(pWixLoc->rgLocControls); } ReleaseObject(pixn); ReleaseObject(pixnl); return hr; }
static HRESULT GetUserAccountName( LPCWSTR pwzKey, LPWSTR* ppwzAccount ) { HRESULT hr = S_OK; PMSIHANDLE hView, hRecKey, hRec; LPWSTR pwzDomain = NULL; LPWSTR pwzName = NULL; // create parameter record hRecKey = ::MsiCreateRecord(1); ExitOnNull(hRecKey, hr, E_OUTOFMEMORY, "Failed to create record"); hr = WcaSetRecordString(hRecKey, 1, pwzKey); ExitOnFailure(hr, "Failed to set record string"); // open view hr = WcaOpenView(vcsUserQuery, &hView); ExitOnFailure(hr, "Failed to open view on User table"); hr = WcaExecuteView(hView, hRecKey); ExitOnFailure(hr, "Failed to execute view on User table"); // fetch record hr = WcaFetchSingleRecord(hView, &hRec); if (S_FALSE == hr) ExitOnFailure(hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "User not found, key: %S", pwzKey); ExitOnFailure(hr, "Failed to fetch user record"); // get user domain hr = WcaGetRecordFormattedString(hRec, uqDomain, &pwzDomain); ExitOnFailure(hr, "Failed to get domain"); // get user name hr = WcaGetRecordFormattedString(hRec, uqName, &pwzName); ExitOnFailure(hr, "Failed to get name"); // build account name hr = CpiBuildAccountName(pwzDomain, pwzName, ppwzAccount); ExitOnFailure(hr, "Failed to build account name"); hr = S_OK; LExit: // clean up ReleaseStr(pwzDomain); ReleaseStr(pwzName); return hr; }
HRESULT CpiResetObjectProperty( ICatalogCollection* piColl, ICatalogObject* piObj, LPCWSTR pwzPropName ) { HRESULT hr = S_OK; BSTR bstrPropName = NULL; long lChanges = 0; VARIANT vtVal; ::VariantInit(&vtVal); // allocate property name string bstrPropName = ::SysAllocString(pwzPropName); ExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "Failed to allocate deleteable property name string"); // get value hr = piObj->get_Value(bstrPropName, &vtVal); ExitOnFailure(hr, "Failed to get deleteable property value"); hr = ::VariantChangeType(&vtVal, &vtVal, 0, VT_BOOL); ExitOnFailure(hr, "Failed to change variant type"); // if the deleteable property is set if (VARIANT_FALSE == vtVal.boolVal) { // clear property vtVal.boolVal = VARIANT_TRUE; hr = piObj->put_Value(bstrPropName, vtVal); ExitOnFailure(hr, "Failed to get property value"); // save changes hr = piColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); } hr = S_OK; LExit: // clean up ReleaseBSTR(bstrPropName); ::VariantClear(&vtVal); return hr; }
static __callback UINT FAR DIAMONDAPI CabExtractWrite(__in INT_PTR hf, __in void FAR *pv, __in UINT cb) { HRESULT hr = S_OK; DWORD cbWrite = 0; ExitOnNull(hf, hr, E_INVALIDARG, "Failed to write file during cabinet extraction - no file given to write"); if (!::WriteFile(reinterpret_cast<HANDLE>(hf), pv, cb, &cbWrite, NULL)) { ExitWithLastError(hr, "failed to write during cabinet extraction"); } LExit: return FAILED(hr) ? -1 : cbWrite; }
static HRESULT AddPropertyToList( SCA_PROPERTY** ppspList ) { HRESULT hr = S_OK; SCA_PROPERTY* psp = static_cast<SCA_PROPERTY*>(MemAlloc(sizeof(SCA_PROPERTY), TRUE)); ExitOnNull(psp, hr, E_OUTOFMEMORY, "failed to allocate memory for new property list element"); psp->pspNext = *ppspList; *ppspList = psp; LExit: return hr; }
static HRESULT AddVirtualDirToList( __in SCA_VDIR** ppsvdList ) { HRESULT hr = S_OK; SCA_VDIR* psvd = static_cast<SCA_VDIR*>(MemAlloc(sizeof(SCA_VDIR), TRUE)); ExitOnNull(psvd, hr, E_OUTOFMEMORY, "failed to allocate memory for new vdir list element"); psvd->psvdNext= *ppsvdList; *ppsvdList = psvd; LExit: return hr; }
static HRESULT AddGroupToList( __inout SCA_GROUP** ppsgList ) { HRESULT hr = S_OK; SCA_GROUP* psg = static_cast<SCA_GROUP*>(MemAlloc(sizeof(SCA_GROUP), TRUE)); ExitOnNull(psg, hr, E_OUTOFMEMORY, "failed to allocate memory for new group list element"); psg->psgNext = *ppsgList; *ppsgList = psg; LExit: return hr; }
static HRESULT AddUserToList( __inout SCA_USER** ppsuList ) { HRESULT hr = S_OK; SCA_USER* psu = static_cast<SCA_USER*>(MemAlloc(sizeof(SCA_USER), TRUE)); ExitOnNull(psu, hr, E_OUTOFMEMORY, "failed to allocate memory for new user list element"); psu->psuNext = *ppsuList; *ppsuList = psu; LExit: return hr; }
/****************************************************************** PromptToContinue - displays the prompt if the application is still running. ******************************************************************/ static HRESULT PromptToContinue( __in_z LPCWSTR wzApplication, __in_z LPCWSTR wzPrompt ) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; PMSIHANDLE hRecMessage = NULL; DWORD *prgProcessIds = NULL; DWORD cProcessIds = 0; hRecMessage = ::MsiCreateRecord(1); ExitOnNull(hRecMessage, hr, E_OUTOFMEMORY, "Failed to create record for prompt."); er = ::MsiRecordSetStringW(hRecMessage, 0, wzPrompt); ExitOnWin32Error(er, hr, "Failed to set prompt record field string"); do { hr = ProcFindAllIdsFromExeName(wzApplication, &prgProcessIds, &cProcessIds); if (SUCCEEDED(hr) && 0 < cProcessIds) { er = WcaProcessMessage(static_cast<INSTALLMESSAGE>(INSTALLMESSAGE_WARNING | MB_ABORTRETRYIGNORE | MB_DEFBUTTON3 | MB_ICONWARNING), hRecMessage); if (IDABORT == er) { hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); } else if (IDRETRY == er) { hr = S_FALSE; } else if (IDIGNORE == er) { hr = S_OK; } else { ExitOnWin32Error(er, hr, "Unexpected return value from prompt to continue."); } } ReleaseNullMem(prgProcessIds); cProcessIds = 0; } while (S_FALSE == hr); LExit: ReleaseMem(prgProcessIds); return hr; }
static HRESULT AddHttpHeaderToList( __in SCA_HTTP_HEADER** ppshhList ) { HRESULT hr = S_OK; SCA_HTTP_HEADER* pshh = static_cast<SCA_HTTP_HEADER*>(MemAlloc(sizeof(SCA_HTTP_HEADER), TRUE)); ExitOnNull(pshh, hr, E_OUTOFMEMORY, "failed to allocate memory for new http header list element"); pshh->pshhNext = *ppshhList; *ppshhList = pshh; LExit: return hr; }
static HRESULT AddSslCertificateToList( __in SCA_WEB_SSL_CERTIFICATE** ppswscList ) { HRESULT hr = S_OK; SCA_WEB_SSL_CERTIFICATE* pswsc = static_cast<SCA_WEB_SSL_CERTIFICATE*>(MemAlloc(sizeof(SCA_WEB_SSL_CERTIFICATE), TRUE)); ExitOnNull(pswsc, hr, E_OUTOFMEMORY, "failed to allocate memory for new SSL certificate list element"); pswsc->pNext = *ppswscList; *ppswscList = pswsc; LExit: return hr; }
HRESULT CpiVerifyComponentArchitecure( LPCWSTR pwzComponent, BOOL* pfMatchingArchitecture ) { HRESULT hr = S_OK; PMSIHANDLE hView, hRecKey, hRec; int iAttributes = 0; if (S_OK == WcaTableExists(L"Component")) { // create parameter record hRecKey = ::MsiCreateRecord(1); ExitOnNull(hRecKey, hr, E_OUTOFMEMORY, "Failed to create record"); hr = WcaSetRecordString(hRecKey, 1, pwzComponent); ExitOnFailure(hr, "Failed to set record string"); // open view hr = WcaOpenView(vcsComponentAttributesQuery, &hView); ExitOnFailure(hr, "Failed to open view on ActionText table"); hr = WcaExecuteView(hView, hRecKey); ExitOnFailure(hr, "Failed to execute view on ActionText table"); // fetch record hr = WcaFetchSingleRecord(hView, &hRec); if (S_FALSE != hr) { ExitOnFailure(hr, "Failed to fetch component record"); hr = WcaGetRecordInteger(hRec, caqAttributes, &iAttributes); ExitOnFailure(hr, "Failed to get component attributes"); } } // return values #ifdef _WIN64 *pfMatchingArchitecture = 256 == (iAttributes & 256); #else *pfMatchingArchitecture = 256 != (iAttributes & 256); #endif hr = S_OK; LExit: return hr; }
/******************************************************************** WcaCaScriptCreate() - creates the appropriate script for this CustomAction Script Key. ********************************************************************/ extern "C" HRESULT WIXAPI WcaCaScriptCreate( __in WCA_ACTION action, __in WCA_CASCRIPT script, __in BOOL fImpersonated, __in LPCWSTR wzScriptKey, __in BOOL fAppend, __in WCA_CASCRIPT_HANDLE* phScript ) { HRESULT hr = S_OK; LPWSTR pwzScriptPath = NULL; HANDLE hScriptFile = INVALID_HANDLE_VALUE; hr = CaScriptFileName(action, script, fImpersonated, wzScriptKey, &pwzScriptPath); ExitOnFailure(hr, "Failed to calculate script file name."); hScriptFile = ::CreateFileW(pwzScriptPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, fAppend ? OPEN_ALWAYS : CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (INVALID_HANDLE_VALUE == hScriptFile) { ExitWithLastError1(hr, "Failed to open CaScript: %S", pwzScriptPath); } if (fAppend && INVALID_SET_FILE_POINTER == ::SetFilePointer(hScriptFile, 0, NULL, FILE_END)) { ExitWithLastError(hr, "Failed to seek to end of file."); } *phScript = reinterpret_cast<WCA_CASCRIPT_HANDLE>(MemAlloc(sizeof(WCA_CASCRIPT_STRUCT), TRUE)); ExitOnNull(*phScript, hr, E_OUTOFMEMORY, "Failed to allocate space for cascript handle."); (*phScript)->pwzScriptPath = pwzScriptPath; pwzScriptPath = NULL; (*phScript)->hScriptFile = hScriptFile; hScriptFile = INVALID_HANDLE_VALUE; LExit: if (INVALID_HANDLE_VALUE != hScriptFile) { ::CloseHandle(hScriptFile); } ReleaseStr(pwzScriptPath); return hr; }
HRESULT CpiActionDataMessage( DWORD cArgs, ... ) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; PMSIHANDLE hRec; va_list args; // record hRec = ::MsiCreateRecord(cArgs); ExitOnNull(hRec, hr, E_OUTOFMEMORY, "Failed to create record"); va_start(args, cArgs); for (DWORD i = 1; i <= cArgs; i++) { LPCWSTR pwzArg = va_arg(args, WCHAR*); if (pwzArg && *pwzArg) { er = ::MsiRecordSetStringW(hRec, i, pwzArg); ExitOnFailure(hr = HRESULT_FROM_WIN32(er), "Failed to set record field string"); } } va_end(args); // message er = WcaProcessMessage(INSTALLMESSAGE_ACTIONDATA, hRec); if (0 == er || IDOK == er || IDYES == er) { hr = S_OK; } else if (IDABORT == er || IDCANCEL == er) { WcaSetReturnValue(ERROR_INSTALL_USEREXIT); // note that the user said exit hr = S_FALSE; } else hr = E_UNEXPECTED; LExit: return hr; }
extern "C" HRESULT DAPI ShelGetKnownFolder( __out_z LPWSTR* psczFolderPath, __in REFKNOWNFOLDERID rfidFolder ) { HRESULT hr = S_OK; HMODULE hShell32Dll = NULL; PFN_SHGetKnownFolderPath pfn = NULL; LPWSTR pwzPath = NULL; hr = LoadSystemLibrary(L"shell32.dll", &hShell32Dll); if (E_MODNOTFOUND == hr) { TraceError(hr, "Failed to load shell32.dll"); ExitFunction1(hr = E_NOTIMPL); } ExitOnFailure(hr, "Failed to load shell32.dll."); pfn = reinterpret_cast<PFN_SHGetKnownFolderPath>(::GetProcAddress(hShell32Dll, "SHGetKnownFolderPath")); ExitOnNull(pfn, hr, E_NOTIMPL, "Failed to find SHGetKnownFolderPath entry point."); hr = pfn(rfidFolder, KF_FLAG_CREATE, NULL, &pwzPath); ExitOnFailure(hr, "Failed to get known folder path."); hr = StrAllocString(psczFolderPath, pwzPath, 0); ExitOnFailure1(hr, "Failed to copy shell folder path: %ls", pwzPath); hr = PathBackslashTerminate(psczFolderPath); ExitOnFailure1(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath); LExit: if (pwzPath) { ::CoTaskMemFree(pwzPath); } if (hShell32Dll) { ::FreeLibrary(hShell32Dll); } return hr; }
HRESULT ScaWriteProperty( IMSAdminBase* piMetabase, SCA_PROPERTY* psp ) { Assert(piMetabase); HRESULT hr = S_OK; DWORD dwValue; LPWSTR wz = NULL; ExitOnNull(psp, hr, E_INVALIDARG, "Failed to write property because no property to write was given"); // // Figure out what setting we're writing and write it // if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_IIS5_ISOLATION_MODE)) { dwValue = 1; hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_GLOBAL_STANDARD_APP_MODE_ENABLED, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue)); ExitOnFailure(hr, "failed to set IIs5IsolationMode"); } else if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_MAX_GLOBAL_BANDWIDTH)) { dwValue = wcstoul(psp->wzValue, &wz, 10) * 1024; // remember, the value shown is in kilobytes, the value saved is in bytes hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_MAX_GLOBAL_BANDWIDTH, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue)); ExitOnFailure(hr, "failed to set MaxGlobalBandwidth"); } else if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_LOG_IN_UTF8)) { dwValue = 1; hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_GLOBAL_LOG_IN_UTF_8, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue)); ExitOnFailure(hr, "failed to set LogInUTF8"); } else if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_ETAG_CHANGENUMBER)) { dwValue = wcstoul(psp->wzValue, &wz, 10); hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, /*MD_ETAG_CHANGENUMBER*/ 2039, METADATA_INHERIT, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue)); ExitOnFailure(hr, "failed to set EtagChangenumber"); } LExit: return hr; }
extern "C" HRESULT DAPI XmlCreateElement( __in IXMLDOMDocument *pixdDocument, __in_z LPCWSTR wzElementName, __out IXMLDOMElement **ppixnElement ) { if (!ppixnElement || !pixdDocument) { return E_INVALIDARG; } HRESULT hr = S_OK; BSTR bstrElementName = ::SysAllocString(wzElementName); ExitOnNull(bstrElementName, hr, E_OUTOFMEMORY, "failed SysAllocString"); hr = pixdDocument->createElement(bstrElementName, ppixnElement); LExit: ReleaseBSTR(bstrElementName); return hr; }
static HRESULT ParseWxl( __in IXMLDOMDocument* pixd, __out WIX_LOCALIZATION** ppWixLoc ) { HRESULT hr = S_OK; IXMLDOMElement *pWxlElement = NULL; WIX_LOCALIZATION* pWixLoc = NULL; pWixLoc = static_cast<WIX_LOCALIZATION*>(MemAlloc(sizeof(WIX_LOCALIZATION), TRUE)); ExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file."); // read the WixLocalization tag hr = pixd->get_documentElement(&pWxlElement); ExitOnFailure(hr, "Failed to get localization element."); // get the Language attribute if present pWixLoc->dwLangId = WIX_LOCALIZATION_LANGUAGE_NOT_SET; hr = XmlGetAttributeNumber(pWxlElement, L"Language", &pWixLoc->dwLangId); if (S_FALSE == hr) { hr = S_OK; } ExitOnFailure(hr, "Failed to get Language value."); // store the strings and controls in a node list hr = ParseWxlStrings(pWxlElement, pWixLoc); ExitOnFailure(hr, "Parsing localization strings failed."); hr = ParseWxlControls(pWxlElement, pWixLoc); ExitOnFailure(hr, "Parsing localization controls failed."); *ppWixLoc = pWixLoc; pWixLoc = NULL; LExit: ReleaseObject(pWxlElement); ReleaseMem(pWixLoc); return hr; }
extern "C" HRESULT AllocHandleTheme( __in THEME* pTheme, __out HANDLE_THEME** ppHandle ) { HRESULT hr = S_OK; HANDLE_THEME* pHandle = NULL; pHandle = static_cast<HANDLE_THEME*>(MemAlloc(sizeof(HANDLE_THEME), TRUE)); ExitOnNull(pHandle, hr, E_OUTOFMEMORY, "Failed to allocate theme handle."); pHandle->cReferences = 1; pHandle->pTheme = pTheme; *ppHandle = pHandle; pHandle = NULL; LExit: ReleaseMem(pHandle); return hr; }
extern "C" HRESULT DAPI Iis7PutPropertyString( __in IAppHostElement *pElement, __in LPCWSTR wzPropName, __in LPCWSTR wzString ) { HRESULT hr = S_OK; VARIANT vtPut; ::VariantInit(&vtPut); vtPut.vt = VT_BSTR; vtPut.bstrVal = ::SysAllocString(wzString); ExitOnNull(vtPut.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString"); hr = Iis7PutPropertyVariant(pElement, wzPropName, vtPut); LExit: ReleaseVariant(vtPut); return hr; }