compiling a .net application with either a 32-bit or 64-bit dll

落爺英雄遲暮 提交于 2019-12-02 07:16:05

From the description, it sounds like your vb.net application is built with the Any CPU option, which means it would run as a 64-bit application on a 64-bit machine. In that case, it would not load the 32-bit DLL.

Rather than try to use both a 32-bit and 64-bit version, you should be able to just change it to run as 32-bit. Simpler deployment. Under the project properties build tab, choose x86.

Build your tool using the x86 platform (as opposed to Any CPU), and it will be loaded as x86 code even on 64-bit systems.

Or you can do something like

class SharpSvn64 {
    [DllImport("sharpsvn64.dll")] extern public static void DoSomething();
}

class SharpSvn32 {
    [DllImport("sharpsvn32.dll")] extern public static void DoSomething();
}

class SharpSvn {
    static readonly bool Is64 = (IntPtr.Size == 8);

    void DoSomething() {
        if (Is64)
            SharpSvn64.DoSomething();
        else
            SharpSvn32.DoSomething();
    }
}

Edit: Since SharpSVN is managed, PInvoke wouldn't be the answer, so building x86 executables are probably the way. Or, if the interface is identical, you MAY get away with subscribing to the AddDomain.AssemblyResolve event and choose which assembly you want in that. I don't know if this is a good idea, though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!