DWORD GetProgramDir(DWORD nBufferLength, LPTSTR lpBuffer)
{
DWORD dwReturn = 0;
if (nBufferLength <= 0 || lpBuffer == NULL)
return dwReturn;
dwReturn = ::GetModuleFileName(NULL, lpBuffer, nBufferLength);
if (dwReturn <= nBufferLength)
{
// Remove filename from path
LPTSTR tszSlash = _tcsrchr(lpBuffer, static_cast<int>(_T('//')));
if (tszSlash)
*++tszSlash = _T('/0');
}
return dwReturn;
}
Return Values
If the function succeeds, the return value is the length of the string that is copied to the buffer, in TCHARs. If the buffer is too small to hold the module name, the string is truncated to nSize, and the function returns nSize.
If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError .