比如一个dll 在32位下叫abc.dll在64位下叫abc64.dll现code如下
internal const string dll_Filename = "abc.dll"[DLLImport(dll_Filename)]
function1
...
[DLLImport(dll_Filename)]
function2[DLLImport(dll_Filename)]
function3

解决方案 »

  1.   

    using System;
    using System.Runtime.InteropServices;namespace CSharpThings
    {
        internal class Program
        {
            #region Delegates        public delegate void Function1();        #endregion        private static void Main(string[] args)
            {
                Function1 func = null;
                if (IntPtr.Size == 8)
                {
    // 64bit machine
                    func = function1_64;
                }
                else
                {
    // 32 bit machine
                    func = function1_32;
                }            // use func to call the underlying function1
                func();            Console.WriteLine("good");
            }        [DllImport("abc.dll", EntryPoint = "function1")]
            private static extern void function1_32();        [DllImport("abc64.dll", EntryPoint = "function1")]
            private static extern void function1_64();
        }
    }
      

  2.   

    那是不是我在调用function1的过程中 还得判断OS,然后再选用function1_32()或function1_64()?
    这样是不是太麻烦了啊,能不能让我调用函数的时候就用一个形式?