获取dll所在路径

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mpp_king/article/details/89451906
string GetPath()
	{
		string dllPath;
		TCHAR tcFullPath[MAX_PATH];
		char* pChPath = new char[MAX_PATH];
		memset(pChPath,'\0',MAX_PATH);

		GetModuleFileName(::LoadLibrary(L"动态库名称.dll"),tcFullPath,MAX_PATH);

		int iLength;
		iLength = WideCharToMultiByte(CP_ACP, 0, tcFullPath, -1, NULL, 0, NULL, NULL);
		WideCharToMultiByte(CP_ACP, 0, tcFullPath, -1, pChPath, iLength, NULL, NULL);

		string chPath(pChPath,strlen(pChPath));

		string dirPath;

		int pos = chPath.rfind("\\");

		dirPath = chPath.substr(0,pos);

		delete[]pChPath;
		return dirPath;
	}

猜你喜欢

转载自blog.csdn.net/mpp_king/article/details/89451906
今日推荐