获取dll所在路径

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;
	}

 

你可能感兴趣的:(C/C++)