示例#1
0
	//-------------------------------------------------------------------------
	//
	void Log::outString(FILE *file, const char* data, size_t size)
	{
		std::string strTime = currentSystemTime();
		strTime.append(" ");
#if _MSC_VER
		WCHAR str[MAX_QUERY_LEN + 1] = {0};
		
		MultiByteToWideChar(CP_ACP, 0, strTime.c_str(), strTime.size() + 1, str, sizeof(str)/sizeof(str[0]));
		OutputDebugString(str);
		MultiByteToWideChar(CP_ACP, 0, data, size + 1, str, sizeof(str)/sizeof(str[0]));
		str[size] = '\n';
		str[size + 1] = '\0';
		OutputDebugString(str);
#endif 
		printf("%s %s\n", strTime.c_str(), data);

		fwrite(strTime.c_str(), strTime.size(), 1, file);
		fwrite(data, size, 1, file);
	}
示例#2
0
double currentTime()
{
    static bool init = false;
    static double lastTime;
    static DWORD lastTickCount;
    if (!init) {
        lastTime = currentSystemTime();
        lastTickCount = GetTickCount();
        init = true;
        return lastTime;
    }

    DWORD tickCountNow = GetTickCount();
    DWORD elapsed = tickCountNow - lastTickCount;
    double timeNow = lastTime + (double)elapsed / 1000.;
    if (elapsed >= 0x7FFFFFFF) {
        lastTime = timeNow;
        lastTickCount = tickCountNow;
    }
    return timeNow;
}