From 1e7800b811b658659c8487bf2ccb541fdd6bd1be Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 28 Apr 2020 11:17:29 +1000 Subject: Fix bugs around mbanative's InitializeFromCreateArgs. --- .../IBootstrapperApplicationFactory.cs | 17 +++++++++-------- src/balutil/balutil.vcxproj | 4 ++-- src/balutil/packages.config | 2 +- src/bextutil/bextutil.vcxproj | 4 ++-- src/bextutil/packages.config | 2 +- src/mbanative/mbanative.cpp | 2 +- src/mbanative/mbanative.vcxproj | 4 ++-- src/mbanative/packages.config | 2 +- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/WixToolset.Mba.Core/IBootstrapperApplicationFactory.cs b/src/WixToolset.Mba.Core/IBootstrapperApplicationFactory.cs index d3087717..b9c62a99 100644 --- a/src/WixToolset.Mba.Core/IBootstrapperApplicationFactory.cs +++ b/src/WixToolset.Mba.Core/IBootstrapperApplicationFactory.cs @@ -23,19 +23,20 @@ namespace WixToolset.Mba.Core [GeneratedCodeAttribute("WixToolset.Bootstrapper.InteropCodeGenerator", "1.0.0.0")] public struct Command { + // Strings must be declared as pointers so that Marshaling doesn't free them. [MarshalAs(UnmanagedType.I4)] internal int cbSize; [MarshalAs(UnmanagedType.U4)] private readonly LaunchAction action; [MarshalAs(UnmanagedType.U4)] private readonly Display display; [MarshalAs(UnmanagedType.U4)] private readonly Restart restart; - [MarshalAs(UnmanagedType.LPWStr)] private readonly string wzCommandLine; + private readonly IntPtr wzCommandLine; [MarshalAs(UnmanagedType.I4)] private readonly int nCmdShow; [MarshalAs(UnmanagedType.U4)] private readonly ResumeType resume; private readonly IntPtr hwndSplashScreen; [MarshalAs(UnmanagedType.I4)] private readonly RelationType relation; [MarshalAs(UnmanagedType.Bool)] private readonly bool passthrough; - [MarshalAs(UnmanagedType.LPWStr)] private readonly string wzLayoutDirectory; - [MarshalAs(UnmanagedType.LPWStr)] private readonly string wzBootstrapperWorkingFolder; - [MarshalAs(UnmanagedType.LPWStr)] private readonly string wzBootstrapperApplicationDataPath; + private readonly IntPtr wzLayoutDirectory; + private readonly IntPtr wzBootstrapperWorkingFolder; + private readonly IntPtr wzBootstrapperApplicationDataPath; public IBootstrapperCommand GetBootstrapperCommand() { @@ -43,15 +44,15 @@ namespace WixToolset.Mba.Core this.action, this.display, this.restart, - this.wzCommandLine, + Marshal.PtrToStringUni(this.wzCommandLine), this.nCmdShow, this.resume, this.hwndSplashScreen, this.relation, this.passthrough, - this.wzLayoutDirectory, - this.wzBootstrapperWorkingFolder, - this.wzBootstrapperApplicationDataPath); + Marshal.PtrToStringUni(this.wzLayoutDirectory), + Marshal.PtrToStringUni(this.wzBootstrapperWorkingFolder), + Marshal.PtrToStringUni(this.wzBootstrapperApplicationDataPath)); } } diff --git a/src/balutil/balutil.vcxproj b/src/balutil/balutil.vcxproj index b3a43d4c..8c96c002 100644 --- a/src/balutil/balutil.vcxproj +++ b/src/balutil/balutil.vcxproj @@ -2,7 +2,7 @@ - + @@ -90,7 +90,7 @@ 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}. - + diff --git a/src/balutil/packages.config b/src/balutil/packages.config index 38569fda..e9b2d190 100644 --- a/src/balutil/packages.config +++ b/src/balutil/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/src/bextutil/bextutil.vcxproj b/src/bextutil/bextutil.vcxproj index d0f045ed..eb552747 100644 --- a/src/bextutil/bextutil.vcxproj +++ b/src/bextutil/bextutil.vcxproj @@ -2,7 +2,7 @@ - + @@ -79,7 +79,7 @@ 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}. - + diff --git a/src/bextutil/packages.config b/src/bextutil/packages.config index 38569fda..e9b2d190 100644 --- a/src/bextutil/packages.config +++ b/src/bextutil/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/src/mbanative/mbanative.cpp b/src/mbanative/mbanative.cpp index 745b50e7..98ea3c30 100644 --- a/src/mbanative/mbanative.cpp +++ b/src/mbanative/mbanative.cpp @@ -14,7 +14,7 @@ extern "C" HRESULT WINAPI InitializeFromCreateArgs( hr = BalInitializeFromCreateArgs(pArgs, ppEngine); ExitOnFailure(hr, "Failed to initialize Bal."); - memcpy_s(pCommand, pCommand->cbSize, pArgs->pCommand, pArgs->pCommand->cbSize); + memcpy_s(pCommand, pCommand->cbSize, pArgs->pCommand, min(pArgs->pCommand->cbSize, pCommand->cbSize)); LExit: return hr; } diff --git a/src/mbanative/mbanative.vcxproj b/src/mbanative/mbanative.vcxproj index d2e2b90a..0cba46b5 100644 --- a/src/mbanative/mbanative.vcxproj +++ b/src/mbanative/mbanative.vcxproj @@ -2,7 +2,7 @@ - + @@ -69,7 +69,7 @@ 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}. - + diff --git a/src/mbanative/packages.config b/src/mbanative/packages.config index 38569fda..e9b2d190 100644 --- a/src/mbanative/packages.config +++ b/src/mbanative/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file -- cgit v1.2.3-55-g6feb