示例#1
0
 public static extern Boolean DeviceIoControl(
     [In]  IntPtr handle,
     [In]  Int32 dwIoControlCode,
     ref HPTimerHWtruct timer, // [In]  Byte[] lpInBuffer, //[In] IntPtr lpInBuffer,
     [In]  Int32 nInBufferSize,
     [Out] Byte[] lpOutBuffer, //[Out] IntPtr lpOutBuffer,
     [In]  Int32 nOutBufferSize,
     out Int32 lpBytesReturned,
     [In]  IntPtr lpOverlapped);
示例#2
0
        static UInt32 GetTime()
        {
            UInt32 time;

            unsafe
            {
                if (timerAddress == null)
                {
                    IntPtr         handle = IntPtr.Zero;
                    HPTimerHWtruct timerStruct;
                    try
                    {
                        handle = WindowsCESafeNativeMethods.CreateFile("TRC1:", GenericRead | GenericWrite, 0, IntPtr.Zero, OpenExisting, 0, IntPtr.Zero);
                        if (handle == IntPtr.Zero || handle == new IntPtr(-1))
                        {
                            throw new InvalidOperationException("CreateFile returned invalid handle");
                        }

                        timerStruct          = new HPTimerHWtruct();
                        timerStruct.Revision = 1;
                        Int32 bytesReturned;
                        if (!DeviceIoControl(handle, MapTimerHw, ref timerStruct, 20, null, 0, out bytesReturned, IntPtr.Zero))
                        {
                            throw new InvalidOperationException("DeviceIoControl returned 0");
                        }
                    }
                    finally
                    {
                        if (handle != IntPtr.Zero && handle != new IntPtr(-1))
                        {
                            WindowsCESafeNativeMethods.CloseHandle(handle);
                        }
                    }

                    if (timerStruct.TimerRegPtr == IntPtr.Zero)
                    {
                        throw new InvalidOperationException("HPTimerHWStruct.TimerRegPtr is 0");
                    }

                    timerAddress = (UInt32 *)(timerStruct.TimerRegPtr);
                }
                time = *timerAddress;
            }

            return(time);
        }