LegacyWrapper icon indicating copy to clipboard operation
LegacyWrapper copied to clipboard

cant not package with fody ?

Open laomms opened this issue 3 years ago • 10 comments

LegacyWrapper.dll, LegacyWrapper.Common.dll... can not embedded by fody ? if embedded by fody, call exception: The system can't find the specify File

laomms avatar May 25 '22 08:05 laomms

Hello @laomms, please raise a bug at fody.

Kind regards

zalintyre avatar May 26 '22 16:05 zalintyre

I mean these two dlls cannot be packaged by fody into a single file, must exist in the folder directory ?

laomms avatar May 26 '22 23:05 laomms

when call 64bit unmanaged dll in 32bit application, if have pointer related.it will thrown exception: An IntPtr or UIntPtr with an eight byte value cannot be deserialized on a machine with a four byte word size.

	public interface pkeyhelper64Dll : IDisposable
	{
		[LegacyDllMethod(CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		uint GetEditionNameFromId(uint EditionId, out IntPtr EditionName);
	}
	class Program
        {
		static IWrapperConfig _configuration = WrapperConfigBuilder.Create().TargetArchitecture(TargetArchitecture.Amd64).Build();
		public static void Main(string[] args)
                {
                        IntPtr EditionName;
			using (var client = WrapperProxyFactory<pkeyhelper64Dll>.GetInstance(_configuration))
			{
				var hResult = client.GetEditionNameFromId(0x30, out EditionName);
				if (hResult == 0)
                                {
					Console.WriteLine(Marshal.PtrToStringAnsi( EditionName));
                                }
			}
                        Console.Read();
		}
        }

pic

laomms avatar May 27 '22 00:05 laomms

I mean these two dlls cannot be packaged by fody into a single file, must exist in the folder directory ?

This issue is not related to LegacyWrapper, please raise an issue at fody.

zalintyre avatar May 27 '22 20:05 zalintyre

uint

You have declared your out parameter as IntPtr, which is 32 bit wide on your system. The dll will return a pointer that is 64 bit wide. This cannot work this way.

zalintyre avatar May 27 '22 20:05 zalintyre

so how can I get the pointer value

pic

or it need use unsafe code?

	[LegacyDllImport("pkeyhelper.dll")]
	public unsafe interface pkeyhelper64Dll : IDisposable
	{
		[LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
		int GetEditionNameFromId(uint EditionId,  void* EditionName);
	}

laomms avatar May 28 '22 00:05 laomms

As I don't know how your DLL is built, this would be a nice question for StackOverflow.

zalintyre avatar May 29 '22 20:05 zalintyre

this is a windows system dll. call normally under 64 bit assembly:

[DllImport("pkeyhelper.dll", EntryPoint = "GetEditionNameFromId", CharSet = CharSet.Auto)]
public extern static int GetEditionNameFromId1(int EditionId, out UIntPtr EditionName);

[DllImport("pkeyhelper.dll", EntryPoint = "GetEditionNameFromId", CharSet = CharSet.Auto)]
public extern static int GetEditionNameFromId2(int EditionId, out IntPtr EditionName);

public static void Main(string[] args)
{
            UIntPtr EditionName1;
            var hRes = GetEditionNameFromId1(0x30, out EditionName1);
            if (hRes == 0)
            {
                Console.WriteLine(Marshal.PtrToStringUni(unchecked((IntPtr)(long)(ulong)EditionName1))); //normaol
            }

            IntPtr EditionName2;
            hRes = GetEditionNameFromId2(0x30, out EditionName2);
            if (hRes == 0)
            {
                Console.WriteLine(Marshal.PtrToStringUni(EditionName2)); //normaol
            }
}

laomms avatar May 29 '22 22:05 laomms

Have you tried using long as type for the out parameter?

zalintyre avatar Jun 01 '22 20:06 zalintyre

I have tried every type.

laomms avatar Jun 04 '22 03:06 laomms