LegacyWrapper 3.0 released

02.02.2019 Programming .NET C# Legacy Wrapper

Today, I released version 3.0 of my NuGet package LegacyWrapper. LegacyWrapper 3.0 supports calling methods from legacy DLLs with a convenient managed method call.

There’s no need to hard-code the method name anymore:

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

Compared to the old LegacyWrapper interface, this looks much better, doesn’t it? Well, at first, you have to provide some configuration:

1IWrapperConfig configuration = WrapperConfigBuilder.Create()
2        .TargetArchitecture(TargetArchitecture.X86)
3        .Build();

Also, the target interface has to be defined as a native C# interface that inherits from IDisposable:

2public interface IUser32Dll : IDisposable
4    [LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
5    int GetSystemMetrics(int nIndex);

See the attributes on the interface and the method? That’s how you can control DLL loading now.

But that’s it. Really!


LegacyWrapper now uses Castle to generate dynamic proxies. This makes the wrapper client look like a native method call. On the plus side, there are no strings anymore - that means, method names can now easily be refactored.

Therefore, there is no longer the need to:

Other things that changed:

As always, if you notice anything odd regarding LegacyWrapper, you can get in touch on GitHub.

Click here for the original blog post explaining LegacyWrapper.

Click here for the project at GitHub.

Related posts

... some things you might also be interested in

LegacyWrapper 2.1 is out!
20.08.2017 | Programming | .NET C# Legacy Wrapper
Invoking an unmanaged 32bit library out of a 64bit process
28.09.2015 | Programming | .NET C# Legacy Wrapper
UWP-Apps - First Steps [Part 1]
22.03.2016 | Programming | .NET C# UWP WPF