hInstance 可为NULL
或者GetModuleHandle(NULL);等方式获取
TCHAR* GetCurrPath(HINSTANCE hInstance, TCHAR* pPathBuf, int iBufLen)
{
if (pPathBuf == NULL)
{
return NULL;
}
memset(pPathBuf, 0x0, sizeof(TCHAR) * iBufLen);
int iLen = GetModuleFileName(hInstance, pPathBuf, iBufLen - 1);
if (iLen >= 0)
{
TCHAR* pLastPos = wcsrchr(pPathBuf, L'\\');
if (pLastPos != NULL)
{
*(pLastPos + 1) = L'\0';
}
}
return pPathBuf;
}
本文介绍了一个用于获取当前应用程序路径的函数GetCurrPath。该函数通过GetModuleFileName获取指定实例句柄的模块文件全名,并返回去除文件名后的路径。
785

被折叠的 条评论
为什么被折叠?



