00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define MMNODRV // Installable driver support
00017 #define MMNOSOUND // Sound support
00018 #define MMNOWAVE // Waveform support
00019 #define MMNOMIDI // MIDI support
00020 #define MMNOAUX // Auxiliary audio support
00021 #define MMNOMIXER // Mixer support
00022 #define MMNOJOY // Joystick support
00023 #define MMNOMCI // MCI support
00024 #define MMNOMMIO // Multimedia file I/O support
00025 #define MMNOMMSYSTEM // General MMSYSTEM functions
00026
00027 #define WIN32_LEAN_AND_MEAN
00028
00029 #include "CArchTimeWindows.h"
00030 #include <windows.h>
00031 #include <mmsystem.h>
00032
00033 typedef WINMMAPI DWORD (WINAPI *PTimeGetTime)(void);
00034
00035 static double s_freq = 0.0;
00036 static HINSTANCE s_mmInstance = NULL;
00037 static PTimeGetTime s_tgt = NULL;
00038
00039
00040
00041
00042
00043
00044 CArchTimeWindows::CArchTimeWindows()
00045 {
00046 assert(s_freq == 0.0 || s_mmInstance == NULL);
00047
00048 LARGE_INTEGER freq;
00049 if (QueryPerformanceFrequency(&freq) && freq.QuadPart != 0) {
00050 s_freq = 1.0 / static_cast<double>(freq.QuadPart);
00051 }
00052 else {
00053
00054 s_mmInstance = LoadLibrary("winmm");
00055 if (s_mmInstance != NULL) {
00056 s_tgt = (PTimeGetTime)GetProcAddress(s_mmInstance, "timeGetTime");
00057 }
00058 }
00059 }
00060
00061 CArchTimeWindows::~CArchTimeWindows()
00062 {
00063 s_freq = 0.0;
00064 if (s_mmInstance == NULL) {
00065 FreeLibrary(reinterpret_cast<HMODULE>(s_mmInstance));
00066 s_tgt = NULL;
00067 s_mmInstance = NULL;
00068 }
00069 }
00070
00071 double
00072 CArchTimeWindows::time()
00073 {
00074
00075 if (s_freq != 0.0) {
00076 LARGE_INTEGER c;
00077 QueryPerformanceCounter(&c);
00078 return s_freq * static_cast<double>(c.QuadPart);
00079 }
00080 else if (s_tgt != NULL) {
00081 return 0.001 * static_cast<double>(s_tgt());
00082 }
00083 else {
00084 return 0.001 * static_cast<double>(GetTickCount());
00085 }
00086 }