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

后端 未结 2 1123
故里飘歌
故里飘歌 2021-01-23 22:47

I have an application that we wrote here at work that uses the SharpSVN wrapper for SVN. It has served us well of the past few years. However, we have started bringing in 64-bit

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 23:30

    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.

提交回复
热议问题