codefoundryde / legacywrapper Goto Github PK
View Code? Open in Web Editor NEWLegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process (or vice versa).
License: MIT License
LegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process (or vice versa).
License: MIT License
I used a 32 bit DLL method that has void *lp parameter. When IntPtr returned by Marshall.StructureToPtr was passed, DLL method returned invalid pointer error.
Solution is to cast structure to byte array, create a pointer in Codefoundry.LegacyWrapper32 process memory and pass this pointer to DLL method.
Process legacyWrapper32 = Process.GetProcessesByName("Codefoundry.LegacyWrapper32")[0];
IntPtr pnt = Internals.VirtualAllocEx(legacyWrapper32.Handle, IntPtr.Zero, buf.Length, Internals.AllocationType.Commit | Internals.AllocationType.Reserve, Internals.MemoryProtection.ReadWrite);
Hello everyone I chiamao Alex,
I'm trying to use WrapperClient but I have a problem
I get an error by doing this:
private delegate Int32 H264_DVR_Login(string sDVRIP, ushort wDVRPort, string sUserName, string sPassword, out H264_DVR_DEVICEINFO lpDeviceInfo, out int error, SocketStyle socketstyle);
static public Int32 WrapperH264_DVR_Login(string sDVRIP, ushort wDVRPort, string sUserName, string sPassword, out H264_DVR_DEVICEINFO lpDeviceInfo2, out int error, SocketStyle socketstyle)
{
using (var client = new WrapperClient("NetSdk.dll"))
{
error = 0;
H264_DVR_DEVICEINFO lpDeviceInfo = new H264_DVR_DEVICEINFO();
Int32 x = (Int32)client.Invoke<H264_DVR_Login>("H264_DVR_Login", new object[] { sDVRIP,
wDVRPort, sUserName, sPassword, lpDeviceInfo, error, socketstyle });
lpDeviceInfo2 = lpDeviceInfo;
return x;
}
}
ERROR:
System.Runtime.Serialization.SerializationException: 'Il tipo 'TestVideo.H264_DVR_DEVICEINFO' nell'assembly 'TestVideo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' non è contrassegnato come serializzabile.'
THE PROBLEM IS IN Out H264_DVR_DEVICEINFO lpDeviceInfo ???
who can help me?
thank you all
That was just my mistake
Hi,
maybe it's a stupid question but i can't figure this out.
i'm getting file not found exception when i try to call WrapperProxyFactory.
From your samples i see that you specify User32.dll that is located in C:\Windows\System32.
My dll is placed there too since it's a driver.
What am i doing wrong?
thank you
LegacyWrapper32 will try to load a 64bit Assembly at ProcessMessages()
LegacyWrapper32 called Deserialize() method in ProcessMessages() , but I think LegacyWrapper32 can't deserialize 64 bit process object because LegacyWrapper32 can't load 64bit Assembly.
==============
PipeServer.cs
public CallData ReceiveCallRequest()
{
CallData callData = (CallData)_formatter.Deserialize(_pipe);
return callData;
}
==============
Hello,
will be available version 3.0 in nuget store in near future? Becuase I saw latest commit with good changes wich are not published.
greetings and thanks again for this work, I wonder if you have considered the reverse option, using a 64 bit dll in a 32 bit process? I will work to amend the code myself but it's nice to have in nuget if you ever get the chance to do it.
thanks
it seems works without exception but. When I call the function, as a result, I'm getting 0x0000000000000000 which should be something like 0x0186ad58 what causes the issue?
[LegacyDllImport("ste.dll")]
public interface INativeMethods : IDisposable
{
[LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
IIntPtr ste_init_with_environment_info(string dirLocation, string language);
}
public IWrapperConfig Configuration
{
get
{
return _configuration ??= WrapperConfigBuilder.Create().TargetArchitecture(TargetArchitecture.X86).Build();
}
}
using var client = WrapperProxyFactory<INativeMethods>.GetInstance(Configuration);
_steHandle = client.ste_init_with_environment_info(steHomeDirectory, SystemProperties());
Int32 GetStr( out String Str);
Not working, hangs or no Str change.
original:
//[DllImport("x32.dll",
// CallingConvention = CallingConvention.StdCall,
// CharSet = CharSet.Unicode,
// EntryPoint = "GetStr")]
//public static extern Int32 GetStr(
// [MarshalAs(UnmanagedType.BStr)] out String Str
// );
Hello,
btw. nice project!
Can i define the directory of the imported dll dynamically?
Regards
Martin
Hi,
I work for an MSP and one of our clients consistently has a problem with their UPS shipping manager freezing when highlighting an address. They use QuickBooks for everything and they print out shipping labels through quickbooks' UPS shipping manager. When it opens they always highlight the company name and delete it. When they highlight the company name however, it freezes the shipping manager window. The shipping manager is run by legacy wrapper. It only ever happens on one of their computers, and it works correctly on all of their other computers. It doesn't freeze every time they use it, and every time I've used remote desktop to recreate the problem it works as it should without freezing. Last time they left the error message up and it said legacy wrapper has stopped working. In task manager "Codefoundry.LegacyWrapper32.exe LegacyWrapper32 (32 bit)" is the exact name for it if that helps. I have tried uninstalling and reinstalling QuickBooks (legacywrapper is part of quickbooks program file) and it is still happening after that. Any help would be appreciated, thanks.
I get a System.IO.IOException "Pipe is broken." exception inside PipeServer.cs
LegacyWrapper.Transport.PipeServer::SendCallResponse(CallResult callResult)
{
_fromatter.Serialze(_pipe,callResult);
}
I am new to Windows and DLL's. I have an old 32 bit DLL written in Visual Studio 6 c++. I need to make a 64 bit version. I want to use the Legacy Wrapper 3.01 but do not understand where to start or how to do it.
Can someone provide a complete example or instructions?
Thank you in advance.
Hi, how can I call this function which contains two parameters but just one is ref type:
sbyte ReadPressure(sbyte pHandle, ref float pPressure);
I would like to get the value out from the pPressure variable.
BR,
Ilkka
When the native signature is int MyFunction(BSTR * pszVerificationId)
With PInvoke I can do something like
[System.Runtime.InteropServices.DllImportAttribute("TestDLL", EntryPoint = "MyFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern int MyFunction([MarshalAsAttribute(UnmanagedType.BStr)] ref string test);
With LegacyWrapper I don't know how to get it to work
[LegacyDllImport("TestDLL.dll")]
public interface IUser32Dll : IDisposable
{
[LegacyDllMethod(CallingConvention = CallingConvention.StdCall)]
int MyFunction([MarshalAs(UnmanagedType.BStr)]ref String test);
}
But when I call it with
using (var client = WrapperProxyFactory<IUser32Dll>.GetInstance(configuration))
{
client.MyFunction(ref test);
}
I get System.Runtime.Serialization.SerializationException: 'End of Stream encountered before parsing was completed.'
I am trying to call a 32-bit DLL from an asp.net mvc website (which is running in a 64-bit application pool), but I keep getting this exception: "The system cannot find the file specified".
I am certain I'm doing something wrong, could you please point me into the right direction?
I'm using the sample code provided:
namespace Web.Sandbox
{
[LegacyDllImport("User32.dll")]
public interface IUser32Dll : IDisposable
{
[LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
int GetSystemMetrics(int nIndex);
}
public class SandboxWrapper
{
public static void Test()
{
IWrapperConfig configuration = WrapperConfigBuilder.Create().TargetArchitecture(TargetArchitecture.X86).Build();
using (var client = WrapperProxyFactory<IUser32Dll>.GetInstance(configuration))
{
int x = client.GetSystemMetrics(0);
int y = client.GetSystemMetrics(1);
}
}
}
}
Stack trace:
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at LegacyWrapperClient.Transport.PipeConnector..ctor(IFormatter formatter, IWrapperProcessStarter wrapperProcessStarter, PipeStreamFactory pipeStreamFactory, PipeToken pipeToken) in D:\Programmierung\CSharp\LegacyWrapper\LegacyWrapperClient\Transport\PipeConnector.cs:line 60 at DynamicInjectorf689774ad5234e388d4a1b8fc2720cdd(Object[] ) at Ninject.Activation.Context.ResolveInternal(Object scope) at Ninject.Activation.Context.Resolve() at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings) at Ninject.Planning.Targets.Target'1.ResolveWithin(IContext parent) at System.Linq.Enumerable.WhereSelectArrayIterator'2.MoveNext() at System.Linq.Buffer'1..ctor(IEnumerable'1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable'1 source) at Ninject.Activation.Providers.StandardProvider.Create(IContext context) at Ninject.Activation.Context.ResolveInternal(Object scope) at Ninject.Activation.Context.Resolve() at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings) at Ninject.Planning.Targets.Target'1.ResolveWithin(IContext parent) at System.Linq.Enumerable.WhereSelectArrayIterator'2.MoveNext() at System.Linq.Buffer'1..ctor(IEnumerable'1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable'1 source) at Ninject.Activation.Providers.StandardProvider.Create(IContext context) at Ninject.Activation.Context.ResolveInternal(Object scope) at Ninject.Activation.Context.Resolve() at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings) at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters) at LegacyWrapperClient.Client.WrapperProxyFactory1.CreateProxy() in D:\Programmierung\CSharp\LegacyWrapper\LegacyWrapperClient\Client\WrapperProxyFactory.cs:line 43
Hi. I am having a problem running a 32bit c++ dll in 64 .net app. This dll is itself wrapper around a small Usb management Win32_api dll however there seems to be a problem with loading my dll.
I have given the WrapperClient full path to dll, tried giving the function name with a classname ("myClass::NameOfTheFunction") and without ("NameOfTheFunction"). Function is static and takes no arguments (new object[] { }). Still client.Invoke gives me this error.
Any help would be usefull. Thanks!
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: Codefoundry.LegacyWrapper.exe
Problem Signature 02: 1.0.1.0
Problem Signature 03: 560d9972
Problem Signature 04: mscorlib
Problem Signature 05: 4.6.1055.0
Problem Signature 06: 563c0eac
Problem Signature 07: 40fd
Problem Signature 08: 0
Problem Signature 09: System.BadImageFormatException
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
When i tried to run this wrapper using provided configurations i'm getting below error
System.ComponentModel.Win32Exception: 'The system cannot find the file specified'
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at LegacyWrapperClient.ProcessHandling.MockableProcess.Start() in
E:\Codes\LegacyWrapper\LegacyWrapperClient\ProcessHandling\MockableProcess.cs:line 17
i have copied unmanaged 32 bit dll into executing bin folder. what was i messing with?
When I am using this ,
using (var client = new WrapperClient(_isfDllPath, TargetArchitecture.Amd64))
{
fileHandle = (uint)client.Invoke("LoadItemStoreA", new object[] { FileName });
}
My application just got stuck. Nothing is happening. I cannot able to debug. As on the new WrapperClient, it just stuck. Please can you suggest us, what to do for this.
A dll with activex object doesn't expose any method and only exposes a class. How do I use this package?
Hi
I'm in Windows 10 64 bit
I have a 32bit .exe app that call a 32bit plugin .dll (maybe written in C++?) an all works ok, but for many reasons I would like to use the same version of the .dll already builded in 64bit architecture. So I already have both 32 and 64 bit of the plugin .dll in the exactly same version - I have 2 .dll files (one X86 and one X64). Of coruse my app (32bit) cannot directly use the 64bit one. I wonder if is there a way by using this tool to use the 64bit dll in my 32bit app. In this link I attach the 2 .dll files: one is X86 build, and one is X64
<-->
Can I do this? thanks a lot
I am sending private delegate (as shown in Readme) through Invoke function template,
during de-serialization in client, it tries to load my main app assembly and fails.
Any solution to this?
I'd like to "wrap" a 32bit DLL that was written for use with another program (not written by me.)
I know I can include a wrapped DLL to my own VS code, but that's not what I need.
TIA
I'm hoping to create something to stick between an updated-to-64-bit product (A) that will allow it to still use an old 32-bit product (B) that we still use. Product A expects product B to be a 64-bit DLL, so I'm hoping that I can use LegacyWrapper to produce a DLL (that Product A can call) to act as a 64 bit wrapper for the old 32 bit DLL. LegacyWrapper sounds perfect ... except I'm a C programmer (not C++ or C#) and Visual Studio doesn't seem to have a template for a C# DLL and event if it did, I'm not sure all the exported functions and types would match for both the exported functions and the 32-bit functions to be called.
Is what I'm hoping to do possible or must I take (at least) a few months to learn to create all the COM things necessary to create this from scratch?
Would it be possible to sign the assemblies with a strong-name?
Otherwise, we're not able to use this in our project because we sign our assemblies in order to be able to use different versions side by side in the same app domain without conflict.
There's an official how-to, but I could also provide a PR if required.
I am trying to use this on the web server. I place everything in the site's bin folder, but the page complaint with an exception about file not find in start process. So I place all the file in windows\system32\inetsrv
Now it the site gives a request timed out exception.
Hi, I'm trying to call an x86 library from x64 application. When I try to create WrapperProxyFactory variable I got this error:
System.ArgumentException: 'The provided interface type <TFunctions> must be public.
Parameter name: TFunctions'
Using LegacyWrapper 3.0.1.
This is my interface what I try to call (I store it in different file):
[LegacyDllImport("CP5200.dll")]
public interface IUser32Dll : IDisposable
{
[LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
int CP5200_Net_Init(uint dwIP, int nIPPort, uint dwIDCode, int nTimeOut);
[LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
int CP5200_Net_SendTagText(int nCardID, int nWndNo, IntPtr pText, int crColor, int nFontSize, int nSpeed, int nEffect, int nStayTime, int nAlignment);
}
How can I fix that?
Is there a way to run this from a project that is not .NET Framework? I'm currently getting the following exception when trying to get an instance from the WrapperProxyFactory
:
System.TypeLoadException: Could not load type 'System.Runtime.Remoting.RemotingServices' from assembly 'mscorlib, Version=4.0.0.0
Current unit tests in this project test for valid call results with the included test DLL. Tests should be improved to handle edge cases like a missing dll, wrong target architecture, and wrong permissions to execute a call.
There should also be tests if the Wrapper exe terminates correctly in case of a failure.
The current implementation uses a named pipe to enable communication between wrapper and client. This is insecure, because a named pipe can be read by anyone who knows its name.
Either there is a way to encrypt traffic going over the pipe (e.g. TLS), or we switch to another (secure) IPC technology.
Hi,
I noticed that to reference a method within a DLL, I would have to create an interface that contained a method with the same name as the method in the DLL. This has worked out perfectly for the majority of my DLLs, but no so great for one of them that has entry point names like "_initEth488@4". I believe the "@4" part is causing the problem - I can't create a method with the name "_initEth488@4" due to formatting issues. When I tried to create a method with the name "_initEth488" I received the error:
EntryPointNotFoundException: Unable to find an entry point named '_initEth488' in DLL [DLL PATH]
I noticed that in previous versions (I tried to use versions 2.1.0, 2.0.1, and 2.0.0) it was required to input the name of the DLL method as a string. This would allow for me to use methods like "_initEth488@4", but unfortunately I ran into a strange bug that caused my app to freeze when it got to the line:
using (var client = new WrapperClient([DLL PATH], TargetArchitecture.X86))
This wrapper seems like it would be the perfect, simple solution to my problem if I could get it working. Any help would be greatly appreciated.
Thanks!
Hi,
Got EntryPointNotFoundException while trying to load c# class 32 bit dll in a 64bit console application.
Please help to resolve this.
Thanks,
Does this LegacyWrapper have support for ARM64 systems? And if not, then could it be added in the near future?
Hello,
I know that System.Runtime.Remoting is not existing in net core but did someone has alread tried to find an alternative to run legacyWrapper on net core ?
thanks !
Calling API is too heavy. Are there any tips?
LegacyWrapper.dll, LegacyWrapper.Common.dll... can not embedded by fody ?
if embedded by fody, call exception: The system can't find the specify File
Callbacks are not very likely but any chance of an event coming back from the loaded DLL?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.