Codefoundry.LegacyWrapper 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Codefoundry.LegacyWrapper --version 3.0.0                
NuGet\Install-Package Codefoundry.LegacyWrapper -Version 3.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Codefoundry.LegacyWrapper" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Codefoundry.LegacyWrapper --version 3.0.0                
#r "nuget: Codefoundry.LegacyWrapper, 3.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Codefoundry.LegacyWrapper as a Cake Addin
#addin nuget:?package=Codefoundry.LegacyWrapper&version=3.0.0

// Install Codefoundry.LegacyWrapper as a Cake Tool
#tool nuget:?package=Codefoundry.LegacyWrapper&version=3.0.0                

LegacyWrapper

About

LegacyWrapper uses a wrapper process to call dlls from a process of the opposing architecture (X86 or AMD64).

Since you can't load a dll of another architecture directly, the wrapper utilizes a named pipe to abstract the call. You won't notice this though, because all the magic is hidden behind a single static method.

NuGet Package

There is a NuGet package available here: Codefoundry.LegacyWrapper @ nuget.org

Usage

If you want to compile the LegacyWrapper yourself, make sure to place both the wrapper executable, LegacyWrapperClient.dll and LegacyWrapper.Common.dll in your directory.

// Define a proxy interface with matching method names and signatures
// The interface must be derived from IDisposable!
[LegacyDllImport("User32.dll")]
public interface IUser32Dll : IDisposable
{
    [LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
    int GetSystemMetrics(int nIndex);
}

// Create configuration
IWrapperConfig configuration = WrapperConfigBuilder.Create()
        .TargetArchitecture(TargetArchitecture.X86)
        .Build();

// Create new Wrapper client providing the proxy interface
// Remember to ensure a call to the Dispose()-Method!
using (var client = WrapperProxyFactory<IUser32Dll>.GetInstance(configuration))
{
    // Make calls - it's that simple!
    int x = client.GetSystemMetrics(0);
    int y = client.GetSystemMetrics(1);
}

Please note that loading a 64bit dll will only work on 64bit operating systems.

Further reading

View this blog post to obtain a basic understanding of how the library works internally.

Contributing

Feel free to submit any suggestions/issues and contribute to LegacyWrapper.

License

Copyright (c) 2019, Franz Wimmer. (MIT License)

See LICENSE for more info.

Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1 3,406 2/4/2019
3.0.0 719 2/3/2019
2.1.0 1,622 8/20/2017
2.0.1 2,116 2/17/2017
2.0.0 1,142 2/17/2017
1.1.0 1,116 2/17/2017
1.0.1 1,559 10/1/2015
1.0.0 1,477 9/30/2015