Пример #1
0
        static NativeMethods()
        {
            IntPtr chromaSdkPointer;

            if (EnvironmentHelper.Is64BitProcess() && EnvironmentHelper.Is64BitOperatingSystem())
            {
                // We are running 64-bit!
                chromaSdkPointer = Native.Kernel32.NativeMethods.LoadLibrary("RzChromaSDK64.dll");
            }
            else
            {
                // We are running 32-bit!
                chromaSdkPointer = Native.Kernel32.NativeMethods.LoadLibrary("RzChromaSDK.dll");
            }

            if (chromaSdkPointer == IntPtr.Zero)
            {
                throw new ColoreException(
                          "Failed to dynamically load Chroma SDK library (Error " + Marshal.GetLastWin32Error() + ").");
            }

            Init = GetDelegateFromLibrary <InitDelegate>(chromaSdkPointer, "Init");

            UnInit = GetDelegateFromLibrary <UnInitDelegate>(chromaSdkPointer, "UnInit");

            CreateEffect = GetDelegateFromLibrary <CreateEffectDelegate>(chromaSdkPointer, "CreateEffect");

            CreateKeyboardEffect = GetDelegateFromLibrary <CreateKeyboardEffectDelegate>(
                chromaSdkPointer,
                "CreateKeyboardEffect");

            CreateMouseEffect = GetDelegateFromLibrary <CreateMouseEffectDelegate>(chromaSdkPointer, "CreateMouseEffect");

            CreateHeadsetEffect = GetDelegateFromLibrary <CreateHeadsetEffectDelegate>(
                chromaSdkPointer,
                "CreateHeadsetEffect");

            CreateMousepadEffect = GetDelegateFromLibrary <CreateMousepadEffectDelegate>(
                chromaSdkPointer,
                "CreateMousepadEffect");

            CreateKeypadEffect = GetDelegateFromLibrary <CreateKeypadEffectDelegate>(
                chromaSdkPointer,
                "CreateKeypadEffect");

            DeleteEffect = GetDelegateFromLibrary <DeleteEffectDelegate>(chromaSdkPointer, "DeleteEffect");

            SetEffect = GetDelegateFromLibrary <SetEffectDelegate>(chromaSdkPointer, "SetEffect");

            RegisterEventNotification = GetDelegateFromLibrary <RegisterEventNotificationDelegate>(
                chromaSdkPointer,
                "RegisterEventNotification");

            UnregisterEventNotification = GetDelegateFromLibrary <UnregisterEventNotificationDelegate>(
                chromaSdkPointer,
                "UnregisterEventNotification");

            QueryDevice = GetDelegateFromLibrary <QueryDeviceDelegate>(chromaSdkPointer, "QueryDevice");
        }
Пример #2
0
        static NativeMethods()
        {
            // Get the current processor architecture the CLR is running as
            PortableExecutableKinds peKind;
            ImageFileMachine        machine;

            typeof(object).Module.GetPEKind(out peKind, out machine);

            switch (machine)
            {
            case ImageFileMachine.AMD64:
            case ImageFileMachine.IA64:
                // We are running 64-bit!
                ChromaSdkPointer   = Native.Kernel32.NativeMethods.LoadLibrary("RzChromaSDK64.dll");
                SystemArchitecture = Architecture.X64;
                break;

            case ImageFileMachine.I386:
                // We are running 32-bit!
                ChromaSdkPointer   = Native.Kernel32.NativeMethods.LoadLibrary("RzChromaSDK.dll");
                SystemArchitecture = Architecture.X86;
                break;

            default:
                throw new ColoreException("Unsupported system platform: " + machine);
            }

            if (ChromaSdkPointer == IntPtr.Zero)
            {
                throw new ColoreException("Failed to dynamically load Chroma SDK library.");
            }

            Init = GetDelegateFromLibrary <InitDelegate>(ChromaSdkPointer, "Init");

            UnInit = GetDelegateFromLibrary <UnInitDelegate>(ChromaSdkPointer, "UnInit");

            CreateKeyboardEffect = GetDelegateFromLibrary <CreateKeyboardEffectDelegate>(
                ChromaSdkPointer,
                "CreateKeyboardEffect");

            CreateKeyboardCustomEffects = GetDelegateFromLibrary <CreateKeyboardCustomEffectsDelegate>(
                ChromaSdkPointer,
                "CreateKeyboardCustomEffects");

            CreateKeyboardCustomGridEffects =
                GetDelegateFromLibrary <CreateKeyboardCustomGridEffectsDelegate>(
                    ChromaSdkPointer,
                    "CreateKeyboardCustomGridEffects");

            //CreateMouseEffect = GetDelegateFromLibrary<CreateMouseEffectDelegate>(ChromaSdkPointer, "CreateMouseEffect");

            //CreateMouseCustomEffects = GetDelegateFromLibrary<CreateMouseCustomEffectsDelegate>(
            //    ChromaSdkPointer,
            //    "CreateMouseCustomEffects");

            DeleteEffect = GetDelegateFromLibrary <DeleteEffectDelegate>(ChromaSdkPointer, "DeleteEffect");

            SetEffect = GetDelegateFromLibrary <SetEffectDelegate>(ChromaSdkPointer, "SetEffect");

            RegisterEventNotification = GetDelegateFromLibrary <RegisterEventNotificationDelegate>(
                ChromaSdkPointer,
                "RegisterEventNotification");

            UnregisterEventNotification = GetDelegateFromLibrary <UnregisterEventNotificationDelegate>(
                ChromaSdkPointer,
                "UnregisterEventNotification");
        }