aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Bal/Samples/bafunctions/Readme.txt
blob: 517d0d4c377dfc348bda93644d19914e88749079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

This is a sample project showing how to create a BA function assembly.

The four interfaces are in the WixSampleBAFunctions.cpp file.


Example code:
~~~~~~~~~~~~~


        HRESULT hr = S_OK;
        HKEY hkKey = NULL;
        LPWSTR sczValue = NULL;
        LPWSTR sczFormatedValue = NULL;


        //---------------------------------------------------------------------------------------------
        // Example of BA function failure
        hr = E_NOTIMPL;
        BalExitOnFailure(hr, "Test failure.");
        //---------------------------------------------------------------------------------------------

        //---------------------------------------------------------------------------------------------
        // Example of setting a variables
        hr = m_pEngine->SetVariableString(L"Variable1", L"String value");
        BalExitOnFailure(hr, "Failed to set variable.");
        hr = m_pEngine->SetVariableNumeric(L"Variable2", 1234);
        BalExitOnFailure(hr, "Failed to set variable.");
        //---------------------------------------------------------------------------------------------

        //---------------------------------------------------------------------------------------------
        // Example of reading burn variable.
        BalGetStringVariable(L"WixBundleName", &sczValue);
        BalExitOnFailure(hr, "Failed to get variable.");

        hr = m_pEngine->SetVariableString(L"Variable4", sczValue);
        BalExitOnFailure(hr, "Failed to set variable.");
        //---------------------------------------------------------------------------------------------

        ReleaseNullStr(sczValue); // Release string so it can be re-used

        //---------------------------------------------------------------------------------------------
        // Examples of reading burn variable and formatting it.
        BalGetStringVariable(L"InstallFolder", &sczValue);
        BalExitOnFailure(hr, "Failed to get variable.");

        hr = m_pEngine->SetVariableString(L"Variable5", sczValue);
        BalExitOnFailure(hr, "Failed to set variable.");

        BalFormatString(sczValue, &sczFormatedValue);
        BalExitOnFailure(hr, "Failed to format variable.");

        hr = m_pEngine->SetVariableString(L"Variable6", sczFormatedValue);
        BalExitOnFailure(hr, "Failed to set variable.");
        //---------------------------------------------------------------------------------------------

        ReleaseNullStr(sczValue); // Release string so it can be re-used

        //---------------------------------------------------------------------------------------------
        // Example of reading 64 bit registry and setting the InstallFolder variable to the value read.
        hr = RegOpen(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5", KEY_READ | KEY_WOW64_64KEY, &hkKey);
        BalExitOnFailure(hr, "Failed to open registry key.");

        hr = RegReadString(hkKey, L"InstallPath", &sczValue);
        BalExitOnFailure(hr, "Failed to read registry value.");

        // Example of function call
        PathBackslashTerminate(&sczValue);

        hr = m_pEngine->SetVariableString(L"InstallFolder", sczValue);
        BalExitOnFailure(hr, "Failed to set variable.");
        //---------------------------------------------------------------------------------------------

        ReleaseNullStr(sczValue); // Release string so it can be re-used

        //---------------------------------------------------------------------------------------------
        // Example of calling a function that return HRESULT
        hr = GetFileVersion();
        BalExitOnFailure(hr, "Failed to get version.");
        //---------------------------------------------------------------------------------------------

    LExit:
        ReleaseRegKey(hkKey);
        ReleaseStr(sczValue);
        ReleaseStr(sczFormatedValue);