Exemplo n.º 1
0
        public static void Start(UpdateCallback callback)
        {
            if (!DLLAvailable())
            {
                return;
            }

            // Make a wrapper to convert from the native enum to SMXUpdateCallbackReason.
            InternalUpdateCallback NewCallback = delegate(int PadNumber, int reason, IntPtr user) {
                SMXUpdateCallbackReason ReasonEnum = (SMXUpdateCallbackReason)Enum.ToObject(typeof(SMXUpdateCallbackReason), reason);
                callback(PadNumber, ReasonEnum);
            };

            if (callback == null)
            {
                NewCallback = null;
            }

            SMX_Start(NewCallback, IntPtr.Zero);

            // Keep a reference to the delegate, so it isn't garbage collected.  Do this last.  Once
            // we do this the old callback may be collected, so we want to be sure that native code
            // has already updated the callback.
            CurrentUpdateCallback = NewCallback;

            Console.WriteLine("Struct sizes (C#): " +
                              Marshal.SizeOf(typeof(SMXConfig)) + " " +
                              Marshal.SizeOf(typeof(SMXInfo)) + " " +
                              Marshal.SizeOf(typeof(SMXSensorTestModeData)));
        }
Exemplo n.º 2
0
        public static void Start(UpdateCallback callback)
        {
            if (!DLLAvailable())
            {
                return;
            }

            // Sanity check SMXConfig, which should be 250 bytes.  If this is incorrect,
            // check the padding array.
            {
                SMXConfig config = new SMXConfig();
                int       bytes  = Marshal.SizeOf(config);
                if (bytes != 250)
                {
                    throw new Exception("SMXConfig is " + bytes + " bytes, but should be 250 bytes");
                }
            }

            // Make a wrapper to convert from the native enum to SMXUpdateCallbackReason.
            InternalUpdateCallback NewCallback = delegate(int PadNumber, int reason, IntPtr user) {
                SMXUpdateCallbackReason ReasonEnum = (SMXUpdateCallbackReason)Enum.ToObject(typeof(SMXUpdateCallbackReason), reason);
                callback(PadNumber, ReasonEnum);
            };

            if (callback == null)
            {
                NewCallback = null;
            }

            SMX_Start(NewCallback, IntPtr.Zero);

            // Keep a reference to the delegate, so it isn't garbage collected.  Do this last.  Once
            // we do this the old callback may be collected, so we want to be sure that native code
            // has already updated the callback.
            CurrentUpdateCallback = NewCallback;

            Console.WriteLine("Struct sizes (C#): " +
                              Marshal.SizeOf(typeof(SMXConfig)) + " " +
                              Marshal.SizeOf(typeof(SMXInfo)) + " " +
                              Marshal.SizeOf(typeof(SMXSensorTestModeData)));
        }
Exemplo n.º 3
0
 private static extern void SMX_Start(
     [MarshalAs(UnmanagedType.FunctionPtr)] InternalUpdateCallback callback,
     IntPtr user);