aboutsummaryrefslogtreecommitdiff
path: root/src/Samples
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2018-12-31 23:52:58 -0600
committerSean Hall <r.sean.hall@gmail.com>2018-12-31 23:52:58 -0600
commit2c568de11510b453f499827919964badef22304e (patch)
treedd342fa59ad9b986e375c4128726b505ae95ad67 /src/Samples
parentcd23c2cba4239f32abf9743ecec9fef58136e0e8 (diff)
downloadwix-2c568de11510b453f499827919964badef22304e.tar.gz
wix-2c568de11510b453f499827919964badef22304e.tar.bz2
wix-2c568de11510b453f499827919964badef22304e.zip
Import code from old v4 repo
Diffstat (limited to 'src/Samples')
-rw-r--r--src/Samples/bafunctions/Readme.txt85
-rw-r--r--src/Samples/bafunctions/WixSampleBAFunctions.cpp95
-rw-r--r--src/Samples/bafunctions/bafunctions.cpp46
-rw-r--r--src/Samples/bafunctions/bafunctions.def6
-rw-r--r--src/Samples/bafunctions/bafunctions.rc118
-rw-r--r--src/Samples/bafunctions/bafunctions.vcxproj54
-rw-r--r--src/Samples/bafunctions/bafunctionsver.h13
-rw-r--r--src/Samples/bafunctions/precomp.h47
-rw-r--r--src/Samples/bafunctions/resource.h15
9 files changed, 479 insertions, 0 deletions
diff --git a/src/Samples/bafunctions/Readme.txt b/src/Samples/bafunctions/Readme.txt
new file mode 100644
index 00000000..517d0d4c
--- /dev/null
+++ b/src/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/Samples/bafunctions/WixSampleBAFunctions.cpp b/src/Samples/bafunctions/WixSampleBAFunctions.cpp
new file mode 100644
index 00000000..531b86a3
--- /dev/null
+++ b/src/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/Samples/bafunctions/bafunctions.cpp b/src/Samples/bafunctions/bafunctions.cpp
new file mode 100644
index 00000000..b20f4230
--- /dev/null
+++ b/src/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/Samples/bafunctions/bafunctions.def b/src/Samples/bafunctions/bafunctions.def
new file mode 100644
index 00000000..6e016dad
--- /dev/null
+++ b/src/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/Samples/bafunctions/bafunctions.rc b/src/Samples/bafunctions/bafunctions.rc
new file mode 100644
index 00000000..9643d240
--- /dev/null
+++ b/src/Samples/bafunctions/bafunctions.rc
@@ -0,0 +1,118 @@
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 <winver.h>
4#include <windows.h>
5#include "bafunctionsver.h"
6
7#define VER_APP
8#define VER_ORIGINAL_FILENAME "bafunctions.dll"
9#define VER_INTERNAL_NAME "bafunctions"
10#define VER_PRODUCT_NAME "WiX Sample BAFunctions"
11#define VER_FILE_DESCRIPTION "WiX Sample BAFunctions"
12
13#ifdef DEBUG
14 #define VER_DEBUG VS_FF_DEBUG
15 #define VER_PRIVATE_BUILD VS_FF_PRIVATEBUILD
16 #define VER_PRE_RELEASE (VS_FF_PRERELEASE | VS_FF_SPECIALBUILD)
17#else
18 #define VER_DEBUG 0
19 #define VER_PRIVATE_BUILD 0
20 #define VER_PRE_RELEASE 0
21#endif
22
23#if defined(VER_APP)
24 #define VER_FILE_TYPE VFT_APP
25#elif defined(VER_DLL)
26 #define VER_FILE_TYPE VFT_DLL
27#elif defined(VER_TYPELIB)
28 #define VER_FILE_TYPE VFT_UNKNOWN
29#else
30 #define VER_FILE_TYPE VFT_UNKNOWN
31#endif
32
33#if defined(VER_LANG_NEUTRAL)
34 #ifndef VER_LANG
35 #define VER_LANG 0x0000
36 #endif
37 #ifndef VER_CP
38 #define VER_CP 0x04E4
39 #endif
40 #ifndef VER_BLOCK
41 #define VER_BLOCK "000004E4"
42 #endif
43#else
44 #ifndef VER_LANG
45 #define VER_LANG 0x0409
46 #endif
47 #ifndef VER_CP
48 #define VER_CP 0x04E4
49 #endif
50 #ifndef VER_BLOCK
51 #define VER_BLOCK "040904E4"
52 #endif
53#endif
54
55#define VER_FILE_VERSION rmj, rmm, rbd, rev
56#define VER_PRODUCT_VERSION rmj, rmm, rbd, rev
57#define VER_FILE_VERSION_STRING szVerMajorMinorBuildRev
58#define VER_PRODUCT_VERSION_STRING VER_FILE_VERSION_STRING
59#define VER_FILE_FLAGS_MASK VS_FFI_FILEFLAGSMASK
60#define VER_FILE_FLAGS (VER_DEBUG | VER_PRIVATE_BUILD | VER_PRE_RELEASE)
61
62#define VER_FILE_OS VOS__WINDOWS32
63
64#define VER_COMPANY_NAME ".NET Foundation"
65#ifndef VER_PRODUCT_NAME
66 #define VER_PRODUCT_NAME "Windows Installer XML (WiX)"
67#endif
68#ifndef VER_FILE_DESCRIPTION
69 #define VER_FILE_DESCRIPTION "Windows Installer XML (WiX) component"
70#endif
71
72#if defined(VER_LEGAL_COPYRIGHT)
73 #error
74#endif
75#define VER_LEGAL_COPYRIGHT "Copyright (c) .NET Foundation and contributors.\240 All rights reserved."
76
77#if !defined(VER_FILE_SUBTYPE)
78 #define VER_FILE_SUBTYPE 0
79#endif
80
81#ifdef RC_INVOKED
82
83VS_VERSION_INFO VERSIONINFO
84FILEVERSION VER_FILE_VERSION
85PRODUCTVERSION VER_PRODUCT_VERSION
86FILEFLAGSMASK VER_FILE_FLAGS_MASK
87FILEFLAGS VER_FILE_FLAGS
88FILEOS VER_FILE_OS
89FILETYPE VER_FILE_TYPE
90FILESUBTYPE VER_FILE_SUBTYPE
91BEGIN
92BLOCK "StringFileInfo"
93 BEGIN
94 BLOCK VER_BLOCK
95 BEGIN
96 VALUE "CompanyName", VER_COMPANY_NAME
97 VALUE "FileDescription", VER_FILE_DESCRIPTION
98 VALUE "FileVersion", VER_FILE_VERSION_STRING
99 VALUE "InternalName", VER_INTERNAL_NAME
100
101 VALUE "LegalCopyright", VER_LEGAL_COPYRIGHT
102
103 VALUE "OriginalFilename", VER_ORIGINAL_FILENAME
104 VALUE "ProductName", VER_PRODUCT_NAME
105 VALUE "ProductVersion", VER_FILE_VERSION_STRING
106#if defined(DEBUG)
107 VALUE "WiX Common Resource Format", "Debug Only"
108#endif
109 END
110 END
111
112BLOCK "VarFileInfo"
113 BEGIN
114 VALUE "Translation", VER_LANG, VER_CP
115 END
116END
117
118#endif
diff --git a/src/Samples/bafunctions/bafunctions.vcxproj b/src/Samples/bafunctions/bafunctions.vcxproj
new file mode 100644
index 00000000..71b27bca
--- /dev/null
+++ b/src/Samples/bafunctions/bafunctions.vcxproj
@@ -0,0 +1,54 @@
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
5<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6 <ItemGroup Label="ProjectConfigurations">
7 <ProjectConfiguration Include="Debug|Win32">
8 <Configuration>Debug</Configuration>
9 <Platform>Win32</Platform>
10 </ProjectConfiguration>
11 <ProjectConfiguration Include="Release|Win32">
12 <Configuration>Release</Configuration>
13 <Platform>Win32</Platform>
14 </ProjectConfiguration>
15 </ItemGroup>
16 <ItemGroup Label="ProjectConfigurations">
17 <ProjectConfiguration Include="Debug|ARM">
18 <Configuration>Debug</Configuration>
19 <Platform>ARM</Platform>
20 </ProjectConfiguration>
21 <ProjectConfiguration Include="Release|ARM">
22 <Configuration>Release</Configuration>
23 <Platform>ARM</Platform>
24 </ProjectConfiguration>
25 </ItemGroup>
26 <PropertyGroup Label="Globals">
27 <ProjectGuid>{EB0A7D51-2133-4EE7-B6CA-87DBEAC67E02}</ProjectGuid>
28 <ConfigurationType>DynamicLibrary</ConfigurationType>
29 <CharacterSet>Unicode</CharacterSet>
30 <TargetName>BAFunctions</TargetName>
31 <ProjectModuleDefinitionFile>bafunctions.def</ProjectModuleDefinitionFile>
32 </PropertyGroup>
33 <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), wix.proj))\tools\WixBuild.props" />
34 <PropertyGroup>
35 <ProjectAdditionalIncludeDirectories>$(WixRoot)src\libs\dutil\inc;$(WixRoot)src\burn\inc;$(WixRoot)src\libs\balutil\inc</ProjectAdditionalIncludeDirectories>
36 <ProjectAdditionalLinkLibraries>comctl32.lib;gdiplus.lib;msimg32.lib;shlwapi.lib;wininet.lib;dutil.lib;balutil.lib;version.lib</ProjectAdditionalLinkLibraries>
37 </PropertyGroup>
38 <ItemGroup>
39 <ClCompile Include="WixSampleBAFunctions.cpp" />
40 <ClCompile Include="bafunctions.cpp" />
41 </ItemGroup>
42 <ItemGroup>
43 <ClInclude Include="precomp.h" />
44 <ClInclude Include="resource.h" />
45 </ItemGroup>
46 <ItemGroup>
47 <None Include="bafunctions.def" />
48 <None Include="Readme.txt" />
49 </ItemGroup>
50 <ItemGroup>
51 <ResourceCompile Include="bafunctions.rc" />
52 </ItemGroup>
53 <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), wix.proj))\tools\WixBuild.targets" />
54</Project>
diff --git a/src/Samples/bafunctions/bafunctionsver.h b/src/Samples/bafunctions/bafunctionsver.h
new file mode 100644
index 00000000..e6e22f4e
--- /dev/null
+++ b/src/Samples/bafunctions/bafunctionsver.h
@@ -0,0 +1,13 @@
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#ifndef _VERSION_FILE_H_
4#define _VERSION_FILE_H_
5
6#define szVerMajorMinor "1.0"
7#define szVerMajorMinorBuildRev "1.0.0.0"
8#define rmj 1
9#define rmm 0
10#define rbd 0
11#define rev 0
12
13#endif
diff --git a/src/Samples/bafunctions/precomp.h b/src/Samples/bafunctions/precomp.h
new file mode 100644
index 00000000..82ce2dae
--- /dev/null
+++ b/src/Samples/bafunctions/precomp.h
@@ -0,0 +1,47 @@
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#include <gdiplus.h>
7#include <msiquery.h>
8#include <objbase.h>
9#include <shlobj.h>
10#include <shlwapi.h>
11#include <stdlib.h>
12#include <strsafe.h>
13#include <CommCtrl.h>
14
15// Standard WiX header files, include as required
16#include "dutil.h"
17//#include "memutil.h"
18//#include "dictutil.h"
19//#include "dirutil.h"
20#include "fileutil.h"
21#include "locutil.h"
22//#include "logutil.h"
23#include "pathutil.h"
24//#include "resrutil.h"
25//#include "shelutil.h"
26#include "strutil.h"
27#include "thmutil.h"
28//#include "uriutil.h"
29//#include "xmlutil.h"
30#include "regutil.h"
31
32//#include "IBootstrapperEngine.h"
33//#include "IBootstrapperApplication.h"
34
35#include "BalBaseBootstrapperApplication.h"
36//#include "balinfo.h"
37//#include "balcondition.h"
38#include "balutil.h"
39
40#include "BAFunctions.h"
41#include "IBAFunctions.h"
42
43HRESULT WINAPI CreateBAFunctions(
44 __in HMODULE hModule,
45 __in const BA_FUNCTIONS_CREATE_ARGS* pArgs,
46 __inout BA_FUNCTIONS_CREATE_RESULTS* pResults
47 );
diff --git a/src/Samples/bafunctions/resource.h b/src/Samples/bafunctions/resource.h
new file mode 100644
index 00000000..149a8ff4
--- /dev/null
+++ b/src/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