Skip to content

Commit

Permalink
Merge pull request #4 from CodefoundryDE/x64
Browse files Browse the repository at this point in the history
X64
  • Loading branch information
Franz Wimmer committed Aug 20, 2017
2 parents fa00ca2 + a781cd5 commit f297a60
Show file tree
Hide file tree
Showing 30 changed files with 644 additions and 64 deletions.
31 changes: 29 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
# LegacyWrapper Changelog

## v1.0.1
## Version 3.0 [20. Aug 2017]

* It is now possible to load 64bit libraries in a 32bit process:

```csharp
using (var client = new WrapperClient(TestDllPath, TargetArchitecture.Amd64))
{
result = (int)client.Invoke<TestStdCallDelegate>("TestStdCall", new object[] { input });
}
```
* Please note that this will only work if the OS is 64 bit.
* As the second optional parameter defaults to X86, this release should be backwards compatible.

## Version 2.0.1 [17. Feb 2017]

* This is a minor release that updates some XML docs.

## Version 2.0 [17. Feb 2017]

* This version 2.0 of LegacyWrapper adds a major performance improvement. The wrapper executable now loads the requested dll only once until disposed.
* LegacyWrapper 2.0 is not backwards compatible.

## Version 1.1.0 [17. Feb 2017]

* Add support for ref parameters (values in passed parameters array will be updated)
* Improve error handling (wrapper exe will not crash randomly any more)

## Version 1.0.1 [1. Oct 2015]

* NuGet package dll is now compiled with AnyCPU (resulted in a BadImageException)
* Add batch file for creating a NuGet package

## v1.0
## Version 1.0 [1. Oct 2015]

* Initial Release
2 changes: 1 addition & 1 deletion CreatePackage.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nuget.exe pack LegacyWrapper\LegacyWrapper.csproj -prop Configuration=Release -build
nuget.exe pack LegacyWrapperClient\LegacyWrapperClient.csproj -prop Configuration=Release -build
6 changes: 3 additions & 3 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyDescription("LegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process.")]
[assembly: AssemblyDescription("LegacyWrapper uses a wrapper process to call dlls from a process of the opposing architecture (X86 or AMD64).")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("codefoundry.de")]
[assembly: AssemblyCopyright("Copyright (c) 2017, Franz Wimmer. (MIT License)")]
Expand All @@ -17,5 +17,5 @@
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]

[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using System.Runtime.Serialization;
using LegacyWrapper.ErrorHandling;

namespace LegacyWrapper.Interop
namespace LegacyWrapper.Common.Interop
{
/// <summary>
/// Represents a native (unmanaged) dynamically loaded library.
Expand Down
6 changes: 6 additions & 0 deletions LegacyWrapper.Common/LegacyWrapper.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ErrorHandling\LegacyWrapperException.cs" />
<Compile Include="Interop\NativeLibrary.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\CallData.cs" />
<Compile Include="Serialization\CallResult.cs" />
<Compile Include="Wrapper\WrapperHelper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Interop\LICENSE" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LegacyWrapper.Common.Interop;
using LegacyWrapper.Common.Serialization;
using LegacyWrapper.ErrorHandling;
using LegacyWrapper.Interop;

namespace LegacyWrapper
namespace LegacyWrapper.Common.Wrapper
{
public class Program
public class WrapperHelper
{
private static readonly IFormatter Formatter = new BinaryFormatter();

/// <summary>
/// Main method of the legacy dll wrapper.
/// Outsourced main method of the legacy dll wrapper.
/// </summary>
/// <param name="args">
/// The first parameter is expected to be a string.
/// The Wrapper will use this string to create a named pipe.
/// </param>
[HandleProcessCorruptedStateExceptions]
static void Main(string[] args)
public static void Call(string[] args)
{
if (args.Length != 2)
{
Expand All @@ -53,7 +50,7 @@ static void Main(string[] args)
using (NativeLibrary library = NativeLibrary.Load(libraryName, NativeLibraryLoadOptions.SearchAll))
{
// Receive CallData from client

while (data.Status != KeepAliveStatus.Close)
{
InvokeFunction(data, pipe, library);
Expand Down
80 changes: 77 additions & 3 deletions LegacyWrapper.sln
Original file line number Diff line number Diff line change
@@ -1,46 +1,120 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26730.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyWrapper", "LegacyWrapper\LegacyWrapper.csproj", "{B7665A68-F19C-4539-9FE1-06B14BA774E3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyWrapper32", "LegacyWrapper32\LegacyWrapper32.csproj", "{B7665A68-F19C-4539-9FE1-06B14BA774E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyWrapper64", "LegacyWrapper64\LegacyWrapper64.csproj", "{91DF95E2-014E-406B-8EBA-98C6B50F9840}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyWrapperClient", "LegacyWrapperClient\LegacyWrapperClient.csproj", "{CBBA289F-8E61-4FEA-8191-2794402C1333}"
ProjectSection(ProjectDependencies) = postProject
{B7665A68-F19C-4539-9FE1-06B14BA774E3} = {B7665A68-F19C-4539-9FE1-06B14BA774E3}
{91DF95E2-014E-406B-8EBA-98C6B50F9840} = {91DF95E2-014E-406B-8EBA-98C6B50F9840}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyWrapperTest", "LegacyWrapperTest\LegacyWrapperTest.csproj", "{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}"
ProjectSection(ProjectDependencies) = postProject
{B7665A68-F19C-4539-9FE1-06B14BA774E3} = {B7665A68-F19C-4539-9FE1-06B14BA774E3}
{91DF95E2-014E-406B-8EBA-98C6B50F9840} = {91DF95E2-014E-406B-8EBA-98C6B50F9840}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{22EB660B-6C72-4378-BF0C-D8A85E0D33B3}"
ProjectSection(SolutionItems) = preProject
Changelog.md = Changelog.md
GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs
LICENSE = LICENSE
Readme.md = Readme.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyWrapper.Common", "LegacyWrapper.Common\LegacyWrapper.Common.csproj", "{B9E346E3-ED4F-4824-B780-825D87BE9D48}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LegacyWrapperTestDll", "LegacyWrapperTestDll\LegacyWrapperTestDll.vcxproj", "{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Debug|x64.ActiveCfg = Debug|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Debug|x64.Build.0 = Debug|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Debug|x86.ActiveCfg = Debug|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Debug|x86.Build.0 = Debug|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Release|Any CPU.Build.0 = Release|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Release|x64.ActiveCfg = Release|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Release|x64.Build.0 = Release|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Release|x86.ActiveCfg = Release|Any CPU
{B7665A68-F19C-4539-9FE1-06B14BA774E3}.Release|x86.Build.0 = Release|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Debug|x64.ActiveCfg = Debug|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Debug|x64.Build.0 = Debug|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Debug|x86.ActiveCfg = Debug|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Debug|x86.Build.0 = Debug|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Release|Any CPU.Build.0 = Release|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Release|x64.ActiveCfg = Release|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Release|x64.Build.0 = Release|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Release|x86.ActiveCfg = Release|Any CPU
{91DF95E2-014E-406B-8EBA-98C6B50F9840}.Release|x86.Build.0 = Release|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Debug|x64.ActiveCfg = Debug|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Debug|x64.Build.0 = Debug|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Debug|x86.ActiveCfg = Debug|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Debug|x86.Build.0 = Debug|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Release|Any CPU.Build.0 = Release|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Release|x64.ActiveCfg = Release|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Release|x64.Build.0 = Release|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Release|x86.ActiveCfg = Release|Any CPU
{CBBA289F-8E61-4FEA-8191-2794402C1333}.Release|x86.Build.0 = Release|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Debug|x64.ActiveCfg = Debug|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Debug|x64.Build.0 = Debug|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Debug|x86.ActiveCfg = Debug|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Debug|x86.Build.0 = Debug|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Release|Any CPU.Build.0 = Release|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Release|x64.ActiveCfg = Release|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Release|x64.Build.0 = Release|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Release|x86.ActiveCfg = Release|Any CPU
{93E6FBF2-3FC7-4770-9DDE-175025B5AA2C}.Release|x86.Build.0 = Release|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Debug|x64.ActiveCfg = Debug|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Debug|x64.Build.0 = Debug|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Debug|x86.ActiveCfg = Debug|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Debug|x86.Build.0 = Debug|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Release|Any CPU.Build.0 = Release|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Release|x64.ActiveCfg = Release|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Release|x64.Build.0 = Release|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Release|x86.ActiveCfg = Release|Any CPU
{B9E346E3-ED4F-4824-B780-825D87BE9D48}.Release|x86.Build.0 = Release|Any CPU
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Debug|Any CPU.ActiveCfg = Debug|Win32
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Debug|x64.ActiveCfg = Debug|x64
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Debug|x64.Build.0 = Debug|x64
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Debug|x86.ActiveCfg = Debug|Win32
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Debug|x86.Build.0 = Debug|Win32
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Release|Any CPU.ActiveCfg = Release|Win32
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Release|x64.ActiveCfg = Release|x64
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Release|x64.Build.0 = Release|x64
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Release|x86.ActiveCfg = Release|Win32
{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {865DAD1E-AF9A-4000-BF74-465B2DA26804}
EndGlobalSection
EndGlobal
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{B7665A68-F19C-4539-9FE1-06B14BA774E3}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LegacyWrapper</RootNamespace>
<AssemblyName>Codefoundry.LegacyWrapper</AssemblyName>
<RootNamespace>LegacyWrapper32</RootNamespace>
<AssemblyName>Codefoundry.LegacyWrapper32</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down Expand Up @@ -50,7 +50,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>LegacyWrapper.Program</StartupObject>
<StartupObject>LegacyWrapper32.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand All @@ -64,7 +64,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Interop\NativeLibrary.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\GlobalAssemblyInfo.cs">
Expand All @@ -73,7 +72,6 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Interop\LICENSE" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
Expand All @@ -92,10 +90,6 @@
<Project>{B9E346E3-ED4F-4824-B780-825D87BE9D48}</Project>
<Name>LegacyWrapper.Common</Name>
</ProjectReference>
<ProjectReference Include="..\LegacyWrapperClient\LegacyWrapperClient.csproj">
<Project>{cbba289f-8e61-4fea-8191-2794402c1333}</Project>
<Name>LegacyWrapperClient</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
21 changes: 21 additions & 0 deletions LegacyWrapper32/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Runtime.ExceptionServices;
using LegacyWrapper.Common.Wrapper;

namespace LegacyWrapper32
{
public class Program
{
/// <summary>
/// Main method of the legacy dll wrapper.
/// </summary>
/// <param name="args">
/// The first parameter is expected to be a string.
/// The Wrapper will use this string to create a named pipe.
/// </param>
[HandleProcessCorruptedStateExceptions]
static void Main(string[] args)
{
WrapperHelper.Call(args);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;
using System.Reflection;

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("LegacyWrapper")]
[assembly: AssemblyProduct("LegacyWrapper")]
[assembly: AssemblyTitle("LegacyWrapper32")]
[assembly: AssemblyProduct("LegacyWrapper32")]
6 changes: 6 additions & 0 deletions LegacyWrapper64/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
Loading

0 comments on commit f297a60

Please sign in to comment.