- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
static bool GetPathToExecutable( std::wstring & sPath )
{
#ifdef WIN32
std::vector<wchar_t> TmpData;
#else
std::vector<char> TmpData;
#endif
static const size_t _nResize = 256;
try
{
TmpData.resize( _nResize );
}
catch( ... )
{
sPath.clear();
return false;
}
while( true )
{
#ifdef WIN32
DWORD iSize = GetModuleFileNameW( NULL, &TmpData[0], (DWORD) TmpData.size() - 1 );
if( GetLastError() == NO_ERROR )
{
sPath.assign( &TmpData[0], iSize );
return true;
}
else if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
{
//
// Unsupported error
//
break;
}
#else
int iSize = readlink( "/proc/self/exe", &TmpData[0], (int) TmpData.size() - 1 );
if( iSize < 0 )
{
//
// Error is occurred
//
break;
}
if( iSize < TmpData.size() - 1 )
{
//
// Store value
//
return LConv::ConvertCharToWstring( sPath, &TmpData[0] );
}
#endif
try
{
TmpData.resize( iSize + _nResize );
}
catch(...)
{
break;
}
}
sPath.clear();
return false;
}