本文整理汇总了C#中FILETIME类的典型用法代码示例。如果您正苦于以下问题:C# FILETIME类的具体用法?C# FILETIME怎么用?C# FILETIME使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FILETIME类属于命名空间,在下文中一共展示了FILETIME类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLastWriteTime
public static DateTime GetLastWriteTime(int hive, String subkey)
{
UIntPtr hKey = UIntPtr.Zero;
int result = RegOpenKeyEx(hive, subkey, 0, KEYREAD, ref hKey);
if (result != 0) {
throw new System.ComponentModel.Win32Exception(result);
}
StringBuilder lpClass = new StringBuilder(1024);
IntPtr lpcbClass = IntPtr.Zero;
IntPtr lpReserved = IntPtr.Zero;
uint lpcSubKeys;
uint lpcbMaxSubKeyLen;
uint lpcbMaxClassLen;
uint lpcValues;
uint lpcbMaxValueNameLen;
uint lpcbMaxValueLen;
uint lpcbSecurityDescriptor;
FILETIME lastWriteTime = new FILETIME();
result = RegQueryInfoKey(hKey, out lpClass, ref lpcbClass, lpReserved, out lpcSubKeys, out lpcbMaxSubKeyLen,
out lpcbMaxClassLen, out lpcValues, out lpcbMaxValueNameLen, out lpcbMaxValueLen,
out lpcbSecurityDescriptor, ref lastWriteTime);
RegCloseKey(hKey);
if (result != 0) {
throw new System.ComponentModel.Win32Exception(result);
}
byte[] high = BitConverter.GetBytes(lastWriteTime.HighDateTime);
byte[] low = BitConverter.GetBytes(lastWriteTime.LowDateTime);
byte[] buff = new byte[high.Length + low.Length];
Buffer.BlockCopy(low, 0, buff, 0, low.Length );
Buffer.BlockCopy(high, 0, buff, low.Length, high.Length );
long time = BitConverter.ToInt64(buff, 0);
return DateTime.FromFileTimeUtc(time);
}
示例2: FiletimeToDateTime
public static DateTime FiletimeToDateTime(FILETIME fileTime)
{
if ((fileTime.dwHighDateTime == Int32.MaxValue) ||
(fileTime.dwHighDateTime == 0 && fileTime.dwLowDateTime == 0))
{
// Not going to fit in the DateTime. In the WinInet APIs, this is
// what happens when there is no FILETIME attached to the cache entry.
// We're going to use DateTime.MinValue as a marker for this case.
return DateTime.MaxValue;
}
//long hFT2 = (((long)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;
//return DateTime.FromFileTimeUtc(hFT2);
SYSTEMTIME syst = new SYSTEMTIME();
SYSTEMTIME systLocal = new SYSTEMTIME();
if (0 == FileTimeToSystemTime(ref fileTime, ref syst))
{
throw new ApplicationException("Error calling FileTimeToSystemTime: " + Marshal.GetLastWin32Error().ToString());
}
if (0 == SystemTimeToTzSpecificLocalTime(IntPtr.Zero, ref syst, out systLocal))
{
throw new ApplicationException("Error calling SystemTimeToTzSpecificLocalTime: " + Marshal.GetLastWin32Error().ToString());
}
return new DateTime(systLocal.Year, systLocal.Month, systLocal.Day, systLocal.Hour, systLocal.Minute, systLocal.Second);
}
示例3: GetFileTime
public static extern int GetFileTime(HANDLE hFile, ref FILETIME lpCreationTime, ref FILETIME lpLastAccessTime, ref FILETIME lpLastWriteTime);
示例4: FileTimeToSystemTime
public static extern Boolean FileTimeToSystemTime(ref FILETIME lpFileTime,
out SYSTEMTIME lpSystemTime);
示例5: CertGetCertificateChain
private static extern unsafe bool CertGetCertificateChain(IntPtr hChainEngine, SafeCertContextHandle pCertContext, FILETIME* pTime, SafeCertStoreHandle hStore, [In] ref CERT_CHAIN_PARA pChainPara, CertChainFlags dwFlags, IntPtr pvReserved, out SafeX509ChainHandle ppChainContext);
示例6: GetThreadTimes
public static extern int GetThreadTimes(IntPtr hThread, ref FILETIME lpCreationTime, ref FILETIME lpExitTime,
ref FILETIME lpKernelTime, ref FILETIME lpUserTime);
示例7: SetFileTime
public static extern int SetFileTime(IntPtr hFile, ref FILETIME lpCreationTime, ref FILETIME lpLastAccessTime,
ref FILETIME lpLastWriteTime);
示例8: CompareFileTime
public static extern int CompareFileTime(ref FILETIME lpFileTime1, ref FILETIME lpFileTime2);
示例9: FileTimeToDosDateTime
public static extern int FileTimeToDosDateTime(ref FILETIME lpFileTime, ref int lpFatDate, ref int lpFatTime);
示例10: SetFileTime
[DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern int SetFileTime(HANDLE hFile, ref FILETIME lpCreationTime, ref FILETIME lpLastAccessTime, ref FILETIME lpLastWriteTime);
示例11: SystemTimeToFileTime
[DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern int SystemTimeToFileTime(ref SYSTEMTIME lpSystemTime, ref FILETIME lpFileTime);
示例12: FileTimeToDosDateTime
[DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern int FileTimeToDosDateTime(ref FILETIME lpFileTime, ref int lpFatDate, ref int lpFatTime);
示例13: FileTimeToLocalFileTime
[DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern int FileTimeToLocalFileTime(ref FILETIME lpFileTime, ref FILETIME lpLocalFileTime);
示例14: DateTime2FileTime
internal static FILETIME DateTime2FileTime(DateTime dateTime)
{
long fileTime = 0;
if (dateTime != DateTime.MinValue) //Checking for MinValue
fileTime = dateTime.ToFileTime();
FILETIME resultingFileTime = new FILETIME();
resultingFileTime.dwLowDateTime = (uint)(fileTime & 0xFFFFFFFF);
resultingFileTime.dwHighDateTime = (uint)(fileTime >> 32);
return resultingFileTime;
}
示例15: FileTime2DateTime
internal static DateTime FileTime2DateTime(FILETIME fileTime)
{
if (fileTime.dwHighDateTime == 0 && fileTime.dwLowDateTime == 0) //Checking for MinValue
return DateTime.MinValue;
long dateTime = (((long)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;
return DateTime.FromFileTime(dateTime);
}