28 Mart 2018 Çarşamba

GetSystemTimeAsFileTime metodu

Giriş 
Açıklaması şöyle.
If you plan to modify file times for specified files, you can convert a date and time of day to a file time by using the SystemTimeToFileTime function. You can also obtain the system time in a FILETIME structure by calling the GetSystemTimeAsFileTime function.

To make a file time easy to display to a user, use the FileTimeToSystemTime function. FileTimeToSystemTime converts the file time and copies the month, day, year, and time of day from the file time to a SYSTEMTIME structure.
Hassasiyeti (precision) 100 nano saniye cinsinden. Windows'un doğruluğu (accuracy) 1562 mikrosaniye yani 1.5 milisaniye civarında.

Metod Windows Epoch'undan beri geçen 100 nano-saniyelik aralık sayısını alabilmemizi sağlar. Bu metod aslında sadece global bir değişkeni okur, donanım seviyesindeki bir register'ı okumadığı için hızlıdır.

Örnek
Şöyle yaparız. 100 nano saniyelik sayaç, milisaniyeye çevrilirken 10000 (on bin) ile bölünür.
FILETIME filetime,filetime2;
GetSystemTimeAsFileTime(&filetime);
Sleep(100);
GetSystemTimeAsFileTime(&filetime2);
ULONGLONG time1,time2;
time1 = (((ULONGLONG) filetime.dwHighDateTime) << 32) + filetime.dwLowDateTime;
time2 = (((ULONGLONG) filetime2.dwHighDateTime) << 32) + filetime2.dwLowDateTime;
printf("ELAPSED TIME IN MS:%d",(int)((time2-time1)/10000));
Windows Epoch'u POSIX Epoch'une çevirmek için şöyle yaparız. 100 nano saniyelik sayaç, mikrosaniyeye çevrilirken 10 ile bölünür.Eğer sonucu nanosaniye olarak isteseydik tt sayısını 100 ile çarpmak gerekirdi.
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
unsigned long long tt = ft.dwHighDateTime;
tt <<=32;
tt |= ft.dwLowDateTime;
tt /=10; //convert to microseconds
tt -= 11644473600000000ULL;//Adjust for POSIX epoch

GetFileTime metodu

Giriş
Filetime için açıklama şöyle
A file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC). The system records file times when applications create, access, and write to files.

14 Mart 2018 Çarşamba

RegOpenKeyEx metodu

Giriş
İmzası şöyle. options ve samdesired parametreleri DWORD ve REGSAM tipinde görünüyor ancak int gibi düşünmek daha kolay
RegOpenKeyEx(HKEY hKey,
             LPCTSTR lpSubKey,
             int ulOptions,
             int samDesired,
             PHKEY phkResult)
HKEY_CLASSES_ROOT
Açıklaması şöyle
HKEY_CLASSES_ROOT is a virtual tree that's actually a merged view of both the per-user HKCU\Software\Classes and HKLM\Software\Classes trees. (It's a leftover from Windows 9x, which didn't have the separation.)

Writes done to HKCR will go to either the personal or system registry depending on your privileges, and depending on whether the key being updated was originally loaded from HKCU or HKLM.
HKEY_LOCAL_MACHINE 
Açıklama yaz

HKEY_CURRENT_USER 
Açıklaması şöyle
HKEY_CURRENT_USER is a virtual mapping of one HKEY_USERS sub-key, roughly speaking the key of the user that started the process. Hence, different processes might have different HKEY_CURRENT_USER mappings.

12 Mart 2018 Pazartesi

11 Mart 2018 Pazar

GetSystemTime metodu

Giriş 
Şu satırı dahil ederiz.
#include <windows.h>
GetLocalTime ile kardeştir. Ayrıca GetSystemTimeAsFileTime ile ilgilidir.

UTC sonuç döndürür. Hassasiyeti (precision) milisaniye cinsinden . Windows'un doğruluğu (accuracy) 15 milisaniye civarında. Şöyle yaparız.
SYSTEMTIME t;
GetSystemTime(&t); // or GetLocalTime(&t)
printf("The system time is: %02d:%02d:%02d.%03d\n", 
        t.wHour, t.wMinute, t.wSecond, t.wMilliseconds);
SYSTEMTIME Yapısı
İçi şöyledir
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
C#
Şöyle yaparız.
[DllImport("kernel32.dll", SetLastError = true)]
private extern static void GetSystemTime(ref SYSTEMTIME systime);

private struct SYSTEMTIME
{
  public ushort wYear;
  public ushort wMonth;
  public ushort wDayOfWeek;
  public ushort wDay;
  public ushort wHour;
  public ushort wMinute;
  public ushort wSecond;
  public ushort wMilliseconds;
}

private static void GetTime()
{
  // Call the native GetSystemTime method
  // with the defined structure.
  SYSTEMTIME stime = new SYSTEMTIME();
  GetSystemTime(ref stime);
}

GetLocalTime metodu

Giriş
GetSystemTime ile kardeştir.

Örnek
Şöyle yaparız.
SYSTEMTIME sys;
GetLocalTime(&sys);
sprintf(systime, "%4d/%02d/%02d-%02d:%02d:%02d", sys.wYear, sys.wMonth, sys.wDay,alo
  sys.wHour, sys.wMinute, sys.wSecond);