CodefoundryDE / LegacyWrapper

LegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process (or vice versa).
MIT License
80 stars 20 forks source link

return 0x0000000000000000 is value #31

Closed gayan-rb closed 4 years ago

gayan-rb commented 4 years ago

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());
zalintyre commented 4 years ago

Then maybe CallingConvention.Winapi is not the right thing for you? Did you try other calling conventions?

gayan-rb commented 4 years ago

Yes I have others too. when i tried with CallingConvention.ThisCall I'm getting this exception

image

zalintyre commented 4 years ago

You might want to look for the DLL's documentation - they need to state the correct calling convention.

gayan-rb commented 4 years ago

@zalintyre Thanks for the support and awesome project .. I love it

zalintyre commented 4 years ago

Thank you! :) Were you able to solve your problem?

gayan-rb commented 4 years ago

@zalintyre actually I'm trying still I couldn't figure it out what's wrong.!! I posted the same issue on StackOverflow and one guy suggested a path so go on. I'm trying to figure it out. if you get any clue please update the issue I will keep it open. Thank you very mcuh.

zalintyre commented 4 years ago

Is the DLL provided by yourself or a third party library? Are you able to view the library source code?

If the DLL relies on returning pointers to memory addresses, this will not work with legacy wrapper. Because the wrapper will run in a different memory space than your application, you will not be able to access memory the DLL allocates. As someone in that Stackoverflow question suggested, the DLL should return actual result structures instead of pointers.

gayan-rb commented 4 years ago

It's a third party dll. I'm not able to view source code. they have already written a wrapper only for 32 bit. that's why I'm trying to write a wrapper for 64 bit. I can share the source code that I'm trying if you are interested.

zalintyre commented 4 years ago

As I said in my previous comment, if the DLL is only handing out pointers, that won't work with LegacyWrapper.