// getLinkTime.h

#include "getLinkTime.h"

#ifdef _WIN32
#ifdef _MSC_VER
	#pragma comment(lib, "imagehlp.lib")
#endif
#include <Windows.h>
#include <DbgHelp.h>
#include <ctime>

long getLinkTime_L() {
	HMODULE hModule = GetModuleHandle(0);
	return GetTimestampForLoadedLibrary(hModule);
}

std::string getLinkTime_S() {
	char timeBuff[64] = {0};

	time_t linktime = getLinkTime_L();	
	ctime_s(timeBuff, 64, &linktime);

	std::string ret(timeBuff);
	return ret;
}

std::wstring getLinkTime_WS() {
	wchar_t timeBuff[64] = {0};

	time_t linktime = getLinkTime_L();	
	_wctime_s(timeBuff, 64, &linktime);
	
	std::wstring ret(timeBuff);
	return ret;
}

#else /* _WIN32 */

long getLinkTime_L() {
	return 0;
}

std::string getLinkTime_S() {
	return "(unknown)";
}

std::wstring getLinkTime_W() {
	return L"(unknown)";
}

#endif