Example #1
0
        // this static constructor will load the library
        static AppManagerHelper()
        {
            try
             {

            // Initialze the dynamic marshall Infrastructure to call the 32Bit (x86) or the 64Bit (x64) Dll respectively
            SYSTEM_INFO info = new SYSTEM_INFO();
            GetSystemInfo(ref info);

            // Load the correct DLL according to the processor architecture
            switch (info.wProcessorArchitecture)
            {
               case PROCESSOR_ARCHITECTURE.Intel:
                  string pathx86 = AppDomain.CurrentDomain.BaseDirectory;
                  if (!pathx86.EndsWith("\\"))
                     pathx86 += "\\";
                  pathx86 += @"x86\" + DLL_NAME; // Place your X86 DLL name here

                  dllHandle = LoadLibrary(pathx86);
                  if (dllHandle == IntPtr.Zero)
                     throw new DllNotFoundException("x86 DLL not found");
                  break;

               case PROCESSOR_ARCHITECTURE.Amd64:
                  string pathx64 = AppDomain.CurrentDomain.BaseDirectory;
                  if (!pathx64.EndsWith("\\"))
                     pathx64 += "\\";
                  pathx64 += @"x64\" + DLL_NAME; // Place your X64 DLL name here

                  dllHandle = LoadLibrary(pathx64);
                  if (dllHandle == IntPtr.Zero)
                     throw new DllNotFoundException("x64 DLL not found");
                  break;

               default:
                  throw new NotSupportedException("Platform not Supported");
                  break;
            }

            // init the delegate instances with the function delegates of your libaray
            GetAvailProductUpdate = (GetAvailProductUpdateDelegate)GetDelegate("GetAvailProductUpdate", typeof(GetAvailProductUpdateDelegate));

             }
             catch (Exception e)
             {
            if (dllHandle != IntPtr.Zero)
               FreeLibrary(dllHandle);

            throw e;
             }
        }
 public static extern void GetSystemInfo(
     out SYSTEM_INFO lpSystemInfo);
Example #3
0
 public static extern void GetSystemInfo(
     out SYSTEM_INFO lpSystemInfo);