예제 #1
0
 void RefreshDiskSpace()
 {
     if (!WindowsCESafeNativeMethods.GetDiskFreeSpaceEx(driveName,
                                                        out availableAndFreeBytes, out totalBytes, out totalFreeBytes))
     {
         throw new IOException("GetDiskFreeSpaceEx failed");
     }
 }
예제 #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);
        }