Esempio n. 1
0
/********************************************************************
 WcaCaScriptCreateKey() - creates a unique script key for this
                          CustomAction.

********************************************************************/
extern "C" HRESULT WIXAPI WcaCaScriptCreateKey(
    __out LPWSTR* ppwzScriptKey
    )
{
    AssertSz(WcaIsInitialized(), "WcaInitialize() should have been called before calling this function.");
    HRESULT hr = S_OK;

    hr = StrAllocStringAnsi(ppwzScriptKey, WcaGetLogName(), 0, CP_ACP);
    ExitOnFailure(hr, "Failed to create script key.");

LExit:
    return hr;
}
Esempio n. 2
0
/********************************************************************
 WcaGlobalFinalize() - finalizes the Wca library, should be the
                       called once per custom action Dll during
                       DllMain on DLL_PROCESS_DETACH

********************************************************************/
extern "C" void WIXAPI WcaGlobalFinalize()
{
#ifdef DEBUG
    if (WcaIsInitialized())
    {
        CHAR szBuf[2048];
        StringCchPrintfA(szBuf, countof(szBuf), "CustomAction %s called WcaInitialize() but not WcaFinalize()", WcaGetLogName());

        AssertSz(FALSE, szBuf);
    }
#endif
    MemUninitialize();
    g_hInstCADLL = NULL;
}
Esempio n. 3
0
/********************************************************************
 WcaInitializeWow64() - Initializes the Wow64 API

********************************************************************/
extern "C" HRESULT WIXAPI WcaInitializeWow64()
{
    AssertSz(WcaIsInitialized(), "WcaInitialize() should be called before calling WcaInitializeWow64()");
    AssertSz(!WcaIsWow64Initialized(), "WcaInitializeWow64() should not be called twice without calling WcaFinalizeWow64()");

    s_fWow64Initialized = FALSE;
    HRESULT hr = S_OK;
    s_Wow64FSRevertState = NULL;
    s_fWow64FSDisabled = false;

    // Test if we have access to the Wow64 API, and store the result in bWow64APIPresent
    s_hKernel32 = ::GetModuleHandleW(L"kernel32.dll");
    if (!s_hKernel32)
    {
        ExitWithLastError(hr, "failed to get handle to kernel32.dll");
    }

    // This will test if we have access to the Wow64 API
    s_pfnIsWow64Process = (BOOL (*)(HANDLE, PBOOL))::GetProcAddress(s_hKernel32, "IsWow64Process");
    if (NULL != s_pfnIsWow64Process)
    {
        s_pfnDisableWow64 = (BOOL (*)(PVOID *))::GetProcAddress(s_hKernel32, "Wow64DisableWow64FsRedirection");
        // If we fail, log the error but proceed, because we may not need a particular function, or the Wow64 API at all
        if (!s_pfnDisableWow64)
        {
            return S_FALSE;
        }

        s_pfnRevertWow64 = (BOOL (*)(PVOID))::GetProcAddress(s_hKernel32, "Wow64RevertWow64FsRedirection");
        if (!s_pfnRevertWow64)
        {
            return S_FALSE;
        }

        if (s_pfnDisableWow64 && s_pfnRevertWow64)
        {
            s_fWow64Initialized = TRUE;
        }
    }
    else
    {
        return S_FALSE;
    }

LExit:

    return hr;
}
Esempio n. 4
0
/********************************************************************
 WcaLogError() - called before ExitOnXXX() macro exists the function

 NOTE: writes the hresult and error string to the MSI log
********************************************************************/
extern "C" void WcaLogError(
    __in HRESULT hr,
    __in LPCSTR szMessage,
    ...
    )
{
    char szBuffer[LOG_BUFFER];
    va_list dots;

    va_start(dots, szMessage);
    StringCchVPrintfA(szBuffer, countof(szBuffer), szMessage, dots);
    va_end(dots);

    // log the message if using Wca common layer
    if (WcaIsInitialized())
        WcaLog(LOGMSG_STANDARD, "Error 0x%x: %s", hr, szBuffer);
}