-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cpp
52 lines (40 loc) · 1.15 KB
/
Utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/** \file
*/
//---------------------------------------------------------------------------
#include "Utils.h"
#include <windows.h>
#include <assert.h>
//---------------------------------------------------------------------------
HMODULE Utils::GetCurrentModule(void)
{
MEMORY_BASIC_INFORMATION mbi;
static int dummy;
VirtualQuery( &dummy, &mbi, sizeof(mbi) );
return reinterpret_cast<HMODULE>(mbi.AllocationBase);
}
std::string Utils::GetDllPath(void)
{
static char szPath [MAX_PATH + 1] = "";
/** \note
GetModuleFileName behavior:
Windows XP/2000: The string is truncated to
nSize characters and is NOT null terminated if overflowed.
*/
GetModuleFileName (GetCurrentModule(), szPath, MAX_PATH);
szPath[MAX_PATH] = '\0';
return szPath;
}
std::string Utils::ReplaceFileExtension(std::string filename, std::string ext)
{
unsigned int dot = filename.rfind('.');
if (dot == std::string::npos)
return "";
unsigned int bslash = filename.rfind('\\');
if (bslash != std::string::npos)
{
if (bslash > dot)
return "";
}
std::string ret = filename.substr(0, dot) + ext;
return ret;
}