Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant not package with fody ? #42

Open
laomms opened this issue May 25, 2022 · 10 comments
Open

cant not package with fody ? #42

laomms opened this issue May 25, 2022 · 10 comments
Labels

Comments

@laomms
Copy link

laomms commented May 25, 2022

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 laomms added the bug label May 25, 2022
@zalintyre
Copy link
Contributor

Hello @laomms, please raise a bug at fody.

Kind regards

@laomms
Copy link
Author

laomms commented May 26, 2022

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

@laomms
Copy link
Author

laomms commented May 27, 2022

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

@zalintyre
Copy link
Contributor

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
Copy link
Contributor

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.

@laomms
Copy link
Author

laomms commented May 28, 2022

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);
	}

@zalintyre
Copy link
Contributor

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

@laomms
Copy link
Author

laomms commented May 29, 2022

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
            }
}

@zalintyre
Copy link
Contributor

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

@laomms
Copy link
Author

laomms commented Jun 4, 2022

I have tried every type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants