Giter Site home page Giter Site logo

nomissbowling / legacywrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codefoundryde/legacywrapper

0.0 1.0 0.0 406 KB

LegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process.

License: MIT License

Batchfile 0.16% C# 98.20% C++ 1.64%

legacywrapper's Introduction

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 delegate matching DLL function
private delegate int GetSystemMetrics(int index);

// Create new WrapperClient
// Remember to ensure a call to the Dispose()-Method!
using (var client = new WrapperClient("User32.dll"))
{
    // Make calls providing library name, function name, and parameters
    int x = (int)client.Invoke<GetSystemMetrics>("GetSystemMetrics", new object[] { 0 });
    int y = (int)client.Invoke<GetSystemMetrics>("GetSystemMetrics", new object[] { 1 });
}

The constructor takes an optional second parameter where you can specify the target architecture (it defaults to X86):

using (var client = new WrapperClient(TestDllPath, TargetArchitecture.Amd64))
{
    result = (int)client.Invoke<TestStdCallDelegate>("TestStdCall", new object[] { input });
}

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

ref parameters

If your delegate contains ref parameters, the object array passed as parameters to the Invoke<T> method will contain the updated values afterwards.

Todo (maybe)

  • Support for Attributes like [CallingConvention].
  • Type safe usage of generics in Call-Method

Further reading

View this blog post to obtain a basic understanding of how the library works internally. There is also a blog post about the new 64bit feature in LegacyWrapper 2.1.

Contributing

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

License

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

See LICENSE for more info.

Credits

This library includes Nuane.Interop written by Lukas Pokorny.

legacywrapper's People

Contributors

zalintyre avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.