Setting dllimport programmatically in C#

后端 未结 9 1963
情话喂你
情话喂你 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:27

    Why not wrap them into a method?

    private static class ccf_32_64
    {
        private static class ccf_32
        {
            [DllImport(myDllName32)]
            private static extern int func1();
        }
    
        private static class ccf_64
        {
            [DllImport(myDllName64)]
            private static extern int func1();
        }
    
        public static int func1()
        {
            if (32bit)
            {
                return ccf_32.func1();
            }
            else
            {
                return ccf_64.func1();
            }
        }
    }
    

提交回复
热议问题