Setting dllimport programmatically in C#

后端 未结 9 1911
情话喂你
情话喂你 2020-12-30 11:10

I am using DllImport in my solution.
My problem is that I have two versions of the same DLL one built for 32 bit and another for 64 bit.

They both e

9条回答
  •  有刺的猬
    2020-12-30 11:19

    you can create two methods and choose one in a runtime, so you can keep Any CPU

    public static class Ccf
    {
        [DllImport(myDllName32)]
        private static extern int func32();
    
        [DllImport(myDllName64)]
        private static extern int func64();
    
    
        public static int func()
        {
            if(Environment.Is64BitProcess)
            {
                return func64();
            }
            return func32();
        }
    

    }

提交回复
热议问题