/// <summary> /// Create keyboard effect. /// </summary> /// <param name="effect">The type of effect to create.</param> /// <param name="param">Context-sensitive effect parameter.</param> /// <returns>A <see cref="Guid" /> for the created effect.</returns> /// <seealso cref="Razer.NativeMethods.CreateKeyboardEffect" /> internal static Guid CreateKeyboardEffect(Razer.Keyboard.Effects.Effect effect, IntPtr param) { var guid = Guid.Empty; var result = NativeMethods.CreateKeyboardEffect(effect, param, ref guid); if (!result) { throw new NativeCallException("CreateKeyboardEffect", result); } return(guid); }
/// <summary> /// Helper method for creating keyboard effects with relevant structure parameter. /// </summary> /// <typeparam name="T">The structure type, needs to be compatible with the effect type.</typeparam> /// <param name="effect">The type of effect to create.</param> /// <param name="struct">The effect structure parameter.</param> /// <returns>A <see cref="Guid" /> for the created effect.</returns> private static Guid CreateKeyboardEffect <T>(Razer.Keyboard.Effects.Effect effect, T @struct) where T : struct { var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(@struct)); Marshal.StructureToPtr(@struct, ptr, false); try { return(CreateKeyboardEffect(effect, ptr)); } finally { Marshal.FreeHGlobal(ptr); } }
/// <summary> /// Create a keyboard effect without a parameter. /// </summary> /// <param name="effect">The type of effect to create.</param> /// <returns>A <see cref="Guid" /> for the created effect.</returns> /// <remarks>This is currently valid for <see cref="Razer.Keyboard.Effects.Effect.None" /> and <see cref="Razer.Keyboard.Effects.Effect.SpectrumCycling" />.</remarks> internal static Guid CreateKeyboardEffect(Razer.Keyboard.Effects.Effect effect) { return(CreateKeyboardEffect(effect, IntPtr.Zero)); }