aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Bal/Samples/bafunctions
diff options
context:
space:
mode:
Diffstat (limited to 'src/ext/Bal/Samples/bafunctions')
-rw-r--r--src/ext/Bal/Samples/bafunctions/Readme.txt85
-rw-r--r--src/ext/Bal/Samples/bafunctions/WixSampleBAFunctions.cpp95
-rw-r--r--src/ext/Bal/Samples/bafunctions/bafunctions.cpp46
-rw-r--r--src/ext/Bal/Samples/bafunctions/bafunctions.def6
-rw-r--r--src/ext/Bal/Samples/bafunctions/bafunctions.vcxproj81
-rw-r--r--src/ext/Bal/Samples/bafunctions/packages.config7
-rw-r--r--src/ext/Bal/Samples/bafunctions/precomp.h52
-rw-r--r--src/ext/Bal/Samples/bafunctions/resource.h15
8 files changed, 387 insertions, 0 deletions
diff --git a/src/ext/Bal/Samples/bafunctions/Readme.txt b/src/ext/Bal/Samples/bafunctions/Readme.txt
new file mode 100644
index 00000000..517d0d4c
--- /dev/null
+++ b/src/ext/Bal/Samples/bafunctions/Readme.txt
@@ -0,0 +1,85 @@
1
2This is a sample project showing how to create a BA function assembly.
3
4The four interfaces are in the WixSampleBAFunctions.cpp file.
5
6
7Example code:
8~~~~~~~~~~~~~
9
10
11 HRESULT hr = S_OK;
12 HKEY hkKey = NULL;
13 LPWSTR sczValue = NULL;
14 LPWSTR sczFormatedValue = NULL;
15
16
17 //---------------------------------------------------------------------------------------------
18 // Example of BA function failure
19 hr = E_NOTIMPL;
20 BalExitOnFailure(hr, "Test failure.");
21 //---------------------------------------------------------------------------------------------
22
23 //---------------------------------------------------------------------------------------------
24 // Example of setting a variables
25 hr = m_pEngine->SetVariableString(L"Variable1", L"String value");
26 BalExitOnFailure(hr, "Failed to set variable.");
27 hr = m_pEngine->SetVariableNumeric(L"Variable2", 1234);
28 BalExitOnFailure(hr, "Failed to set variable.");
29 //---------------------------------------------------------------------------------------------
30
31 //---------------------------------------------------------------------------------------------
32 // Example of reading burn variable.
33 BalGetStringVariable(L"WixBundleName", &sczValue);
34 BalExitOnFailure(hr, "Failed to get variable.");
35
36 hr = m_pEngine->SetVariableString(L"Variable4", sczValue);
37 BalExitOnFailure(hr, "Failed to set variable.");
38 //---------------------------------------------------------------------------------------------
39
40 ReleaseNullStr(sczValue); // Release string so it can be re-used
41
42 //---------------------------------------------------------------------------------------------
43 // Examples of reading burn variable and formatting it.
44 BalGetStringVariable(L"InstallFolder", &sczValue);
45 BalExitOnFailure(hr, "Failed to get variable.");
46
47 hr = m_pEngine->SetVariableString(L"Variable5", sczValue);
48 BalExitOnFailure(hr, "Failed to set variable.");
49
50 BalFormatString(sczValue, &sczFormatedValue);
51 BalExitOnFailure(hr, "Failed to format variable.");
52
53 hr = m_pEngine->SetVariableString(L"Variable6", sczFormatedValue);
54 BalExitOnFailure(hr, "Failed to set variable.");
55 //---------------------------------------------------------------------------------------------
56
57 ReleaseNullStr(sczValue); // Release string so it can be re-used
58
59 //---------------------------------------------------------------------------------------------
60 // Example of reading 64 bit registry and setting the InstallFolder variable to the value read.
61 hr = RegOpen(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5", KEY_READ | KEY_WOW64_64KEY, &hkKey);
62 BalExitOnFailure(hr, "Failed to open registry key.");
63
64 hr = RegReadString(hkKey, L"InstallPath", &sczValue);
65 BalExitOnFailure(hr, "Failed to read registry value.");
66
67 // Example of function call
68 PathBackslashTerminate(&sczValue);
69
70 hr = m_pEngine->SetVariableString(L"InstallFolder", sczValue);
71 BalExitOnFailure(hr, "Failed to set variable.");
72 //---------------------------------------------------------------------------------------------
73
74 ReleaseNullStr(sczValue); // Release string so it can be re-used
75
76 //---------------------------------------------------------------------------------------------
77 // Example of calling a function that return HRESULT
78 hr = GetFileVersion();
79 BalExitOnFailure(hr, "Failed to get version.");
80 //---------------------------------------------------------------------------------------------
81
82 LExit:
83 ReleaseRegKey(hkKey);
84 ReleaseStr(sczValue);
85 ReleaseStr(sczFormatedValue);
diff --git a/src/ext/Bal/Samples/bafunctions/WixSampleBAFunctions.cpp b/src/ext/Bal/Samples/bafunctions/WixSampleBAFunctions.cpp
new file mode 100644
index 00000000..531b86a3
--- /dev/null
+++ b/src/ext/Bal/Samples/bafunctions/WixSampleBAFunctions.cpp
@@ -0,0 +1,95 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3#include "precomp.h"
4#include "BalBaseBAFunctions.h"
5#include "BalBaseBAFunctionsProc.h"
6
7class CWixSampleBAFunctions : public CBalBaseBAFunctions
8{
9public: // IBootstrapperApplication
10 virtual STDMETHODIMP OnDetectBegin(
11 __in BOOL fInstalled,
12 __in DWORD cPackages,
13 __inout BOOL* pfCancel
14 )
15 {
16 HRESULT hr = S_OK;
17
18 BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running detect begin BA function. fInstalled=%d, cPackages=%u, fCancel=%d", fInstalled, cPackages, *pfCancel);
19
20 //-------------------------------------------------------------------------------------------------
21 // YOUR CODE GOES HERE
22 BalExitOnFailure(hr, "Change this message to represent real error handling.");
23 //-------------------------------------------------------------------------------------------------
24
25 LExit:
26 return hr;
27 }
28
29public: // IBAFunctions
30 virtual STDMETHODIMP OnPlanBegin(
31 __in DWORD cPackages,
32 __inout BOOL* pfCancel
33 )
34 {
35 HRESULT hr = S_OK;
36
37 BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running plan begin BA function. cPackages=%u, fCancel=%d", cPackages, *pfCancel);
38
39 //-------------------------------------------------------------------------------------------------
40 // YOUR CODE GOES HERE
41 BalExitOnFailure(hr, "Change this message to represent real error handling.");
42 //-------------------------------------------------------------------------------------------------
43
44 LExit:
45 return hr;
46 }
47
48public:
49 //
50 // Constructor - initialize member variables.
51 //
52 CWixSampleBAFunctions(
53 __in HMODULE hModule,
54 __in IBootstrapperEngine* pEngine,
55 __in const BA_FUNCTIONS_CREATE_ARGS* pArgs
56 ) : CBalBaseBAFunctions(hModule, pEngine, pArgs)
57 {
58 }
59
60 //
61 // Destructor - release member variables.
62 //
63 ~CWixSampleBAFunctions()
64 {
65 }
66};
67
68
69HRESULT WINAPI CreateBAFunctions(
70 __in HMODULE hModule,
71 __in const BA_FUNCTIONS_CREATE_ARGS* pArgs,
72 __inout BA_FUNCTIONS_CREATE_RESULTS* pResults
73 )
74{
75 HRESULT hr = S_OK;
76 CWixSampleBAFunctions* pBAFunctions = NULL;
77 IBootstrapperEngine* pEngine = NULL;
78
79 // This is required to enable logging functions.
80 hr = BalInitializeFromCreateArgs(pArgs->pBootstrapperCreateArgs, &pEngine);
81 ExitOnFailure(hr, "Failed to initialize Bal.");
82
83 pBAFunctions = new CWixSampleBAFunctions(hModule, pEngine, pArgs);
84 ExitOnNull(pBAFunctions, hr, E_OUTOFMEMORY, "Failed to create new CWixSampleBAFunctions object.");
85
86 pResults->pfnBAFunctionsProc = BalBaseBAFunctionsProc;
87 pResults->pvBAFunctionsProcContext = pBAFunctions;
88 pBAFunctions = NULL;
89
90LExit:
91 ReleaseObject(pBAFunctions);
92 ReleaseObject(pEngine);
93
94 return hr;
95}
diff --git a/src/ext/Bal/Samples/bafunctions/bafunctions.cpp b/src/ext/Bal/Samples/bafunctions/bafunctions.cpp
new file mode 100644
index 00000000..b20f4230
--- /dev/null
+++ b/src/ext/Bal/Samples/bafunctions/bafunctions.cpp
@@ -0,0 +1,46 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3#include "precomp.h"
4
5static HINSTANCE vhInstance = NULL;
6
7extern "C" BOOL WINAPI DllMain(
8 IN HINSTANCE hInstance,
9 IN DWORD dwReason,
10 IN LPVOID /* pvReserved */
11 )
12{
13 switch (dwReason)
14 {
15 case DLL_PROCESS_ATTACH:
16 ::DisableThreadLibraryCalls(hInstance);
17 vhInstance = hInstance;
18 break;
19
20 case DLL_PROCESS_DETACH:
21 vhInstance = NULL;
22 break;
23 }
24
25 return TRUE;
26}
27
28extern "C" HRESULT WINAPI BAFunctionsCreate(
29 __in const BA_FUNCTIONS_CREATE_ARGS* pArgs,
30 __inout BA_FUNCTIONS_CREATE_RESULTS* pResults
31 )
32{
33 HRESULT hr = S_OK;
34
35 hr = CreateBAFunctions(vhInstance, pArgs, pResults);
36 BalExitOnFailure(hr, "Failed to create BAFunctions interface.");
37
38LExit:
39 return hr;
40}
41
42extern "C" void WINAPI BAFunctionsDestroy(
43 )
44{
45 BalUninitialize();
46}
diff --git a/src/ext/Bal/Samples/bafunctions/bafunctions.def b/src/ext/Bal/Samples/bafunctions/bafunctions.def
new file mode 100644
index 00000000..6e016dad
--- /dev/null
+++ b/src/ext/Bal/Samples/bafunctions/bafunctions.def
@@ -0,0 +1,6 @@
1; Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3
4EXPORTS
5 BAFunctionsCreate
6 BAFunctionsDestroy
diff --git a/src/ext/Bal/Samples/bafunctions/bafunctions.vcxproj b/src/ext/Bal/Samples/bafunctions/bafunctions.vcxproj
new file mode 100644
index 00000000..640c812d
--- /dev/null
+++ b/src/ext/Bal/Samples/bafunctions/bafunctions.vcxproj
@@ -0,0 +1,81 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
4<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5 <Import Project="..\..\..\packages\WixToolset.BalUtil.4.0.58\build\WixToolset.BalUtil.props" Condition="Exists('..\..\..\packages\WixToolset.BalUtil.4.0.58\build\WixToolset.BalUtil.props')" />
6 <Import Project="..\..\..\packages\WixToolset.BootstrapperCore.Native.4.0.141\build\WixToolset.BootstrapperCore.Native.props" Condition="Exists('..\..\..\packages\WixToolset.BootstrapperCore.Native.4.0.141\build\WixToolset.BootstrapperCore.Native.props')" />
7 <Import Project="..\..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props" Condition="Exists('..\..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props')" />
8
9 <ItemGroup Label="ProjectConfigurations">
10 <ProjectConfiguration Include="Debug|ARM64">
11 <Configuration>Debug</Configuration>
12 <Platform>ARM64</Platform>
13 </ProjectConfiguration>
14 <ProjectConfiguration Include="Release|ARM64">
15 <Configuration>Release</Configuration>
16 <Platform>ARM64</Platform>
17 </ProjectConfiguration>
18 <ProjectConfiguration Include="Debug|Win32">
19 <Configuration>Debug</Configuration>
20 <Platform>Win32</Platform>
21 </ProjectConfiguration>
22 <ProjectConfiguration Include="Release|Win32">
23 <Configuration>Release</Configuration>
24 <Platform>Win32</Platform>
25 </ProjectConfiguration>
26 <ProjectConfiguration Include="Debug|x64">
27 <Configuration>Debug</Configuration>
28 <Platform>x64</Platform>
29 </ProjectConfiguration>
30 <ProjectConfiguration Include="Release|x64">
31 <Configuration>Release</Configuration>
32 <Platform>x64</Platform>
33 </ProjectConfiguration>
34 </ItemGroup>
35
36 <PropertyGroup Label="Globals">
37 <ProjectGuid>{EB0A7D51-2133-4EE7-B6CA-87DBEAC67E02}</ProjectGuid>
38 <ConfigurationType>DynamicLibrary</ConfigurationType>
39 <PlatformToolset>v142</PlatformToolset>
40 <CharacterSet>Unicode</CharacterSet>
41 <TargetName>BAFunctions</TargetName>
42 <ProjectModuleDefinitionFile>bafunctions.def</ProjectModuleDefinitionFile>
43 </PropertyGroup>
44
45 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
46 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
47
48 <PropertyGroup>
49 <ProjectAdditionalLinkLibraries>comctl32.lib;gdiplus.lib;msimg32.lib;shlwapi.lib;wininet.lib</ProjectAdditionalLinkLibraries>
50 </PropertyGroup>
51 <ItemGroup>
52 <ClCompile Include="WixSampleBAFunctions.cpp" />
53 <ClCompile Include="bafunctions.cpp">
54 <PrecompiledHeader>Create</PrecompiledHeader>
55 </ClCompile>
56 </ItemGroup>
57 <ItemGroup>
58 <ClInclude Include="precomp.h" />
59 <ClInclude Include="resource.h" />
60 </ItemGroup>
61 <ItemGroup>
62 <None Include="bafunctions.def" />
63 <None Include="Readme.txt" />
64 </ItemGroup>
65
66 <ItemGroup>
67 <None Include="packages.config" />
68 </ItemGroup>
69
70 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
71 <Import Project="..\..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets')" />
72 <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
73 <PropertyGroup>
74 <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
75 </PropertyGroup>
76 <Error Condition="!Exists('..\..\..\packages\WixToolset.BalUtil.4.0.58\build\WixToolset.BalUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\WixToolset.BalUtil.4.0.58\build\WixToolset.BalUtil.props'))" />
77 <Error Condition="!Exists('..\..\..\packages\WixToolset.BootstrapperCore.Native.4.0.141\build\WixToolset.BootstrapperCore.Native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\WixToolset.BootstrapperCore.Native.4.0.141\build\WixToolset.BootstrapperCore.Native.props'))" />
78 <Error Condition="!Exists('..\..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props'))" />
79 <Error Condition="!Exists('..\..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets'))" />
80 </Target>
81</Project>
diff --git a/src/ext/Bal/Samples/bafunctions/packages.config b/src/ext/Bal/Samples/bafunctions/packages.config
new file mode 100644
index 00000000..548ddb48
--- /dev/null
+++ b/src/ext/Bal/Samples/bafunctions/packages.config
@@ -0,0 +1,7 @@
1<?xml version="1.0" encoding="utf-8"?>
2<packages>
3 <package id="Nerdbank.GitVersioning" version="3.3.37" targetFramework="native" developmentDependency="true" />
4 <package id="WixToolset.BootstrapperCore.Native" version="4.0.141" targetFramework="native" />
5 <package id="WixToolset.BalUtil" version="4.0.58" targetFramework="native" />
6 <package id="WixToolset.DUtil" version="4.0.72" targetFramework="native" />
7</packages> \ No newline at end of file
diff --git a/src/ext/Bal/Samples/bafunctions/precomp.h b/src/ext/Bal/Samples/bafunctions/precomp.h
new file mode 100644
index 00000000..9d2fe726
--- /dev/null
+++ b/src/ext/Bal/Samples/bafunctions/precomp.h
@@ -0,0 +1,52 @@
1#pragma once
2// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
4
5#include <windows.h>
6
7#pragma warning(push)
8#pragma warning(disable:4458) // declaration of 'xxx' hides class member
9#include <gdiplus.h>
10#pragma warning(pop)
11
12#include <msiquery.h>
13#include <objbase.h>
14#include <shlobj.h>
15#include <shlwapi.h>
16#include <stdlib.h>
17#include <strsafe.h>
18#include <CommCtrl.h>
19
20// Standard WiX header files, include as required
21#include "dutil.h"
22//#include "memutil.h"
23//#include "dictutil.h"
24//#include "dirutil.h"
25#include "fileutil.h"
26#include "locutil.h"
27//#include "logutil.h"
28#include "pathutil.h"
29//#include "resrutil.h"
30//#include "shelutil.h"
31#include "strutil.h"
32#include "thmutil.h"
33//#include "uriutil.h"
34//#include "xmlutil.h"
35#include "regutil.h"
36
37//#include "IBootstrapperEngine.h"
38//#include "IBootstrapperApplication.h"
39
40#include "BalBaseBootstrapperApplication.h"
41//#include "balinfo.h"
42//#include "balcondition.h"
43#include "balutil.h"
44
45#include "BAFunctions.h"
46#include "IBAFunctions.h"
47
48HRESULT WINAPI CreateBAFunctions(
49 __in HMODULE hModule,
50 __in const BA_FUNCTIONS_CREATE_ARGS* pArgs,
51 __inout BA_FUNCTIONS_CREATE_RESULTS* pResults
52 );
diff --git a/src/ext/Bal/Samples/bafunctions/resource.h b/src/ext/Bal/Samples/bafunctions/resource.h
new file mode 100644
index 00000000..149a8ff4
--- /dev/null
+++ b/src/ext/Bal/Samples/bafunctions/resource.h
@@ -0,0 +1,15 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3#define IDC_STATIC -1
4
5
6// Next default values for new objects
7//
8#ifdef APSTUDIO_INVOKED
9#ifndef APSTUDIO_READONLY_SYMBOLS
10#define _APS_NEXT_RESOURCE_VALUE 102
11#define _APS_NEXT_COMMAND_VALUE 40001
12#define _APS_NEXT_CONTROL_VALUE 1003
13#define _APS_NEXT_SYMED_VALUE 101
14#endif
15#endif