在DLL中如何确定自身的文件路径
来源:互联网 发布:武林外传人物分析知乎 编辑:程序博客网 时间:2024/04/27 19:49
Most DLL developers have faced the challenge of detecting a HMODULE/HINSTANCE handle within the module you're running in. It may be a difficult task if you wrote the DLL without a DLLMain() function or you are unaware of its name. For example:
Your DLL was built without ATL/MFC, so the DLLMain() function exists, but it's hidden from you code and you cannot access the hinstDLL parameter. You do not know the DLL's real file name because it could be renamed by everyone, so GetModuleHandle() is not for you.
This small code can help you solve this problem:
#if _MSC_VER >= 1300 // for VC 7.0
// from ATL 7.0 sources
#ifndef _delayimp_h
extern "C" IMAGE_DOS_HEADER __ImageBase;
#endif
#endif
HMODULE GetCurrentModule()
{
#if _MSC_VER < 1300 // earlier than .NET compiler (VC 6.0)
// Here's a trick that will get you the handle of the module
// you're running in without any a-priori knowledge:
// http://www.dotnet247.com/247reference/msgs/13/65259.aspx
MEMORY_BASIC_INFORMATION mbi;
static int dummy;
VirtualQuery( &dummy, &mbi, sizeof(mbi) );
return reinterpret_cast<HMODULE>(mbi.AllocationBase);
#else // VC 7.0
// from ATL 7.0 sources
return reinterpret_cast<HMODULE>(&__ImageBase);
#endif
}
TCHAR fileName[MAX_PATH];
GetModuleFileName(GetCurrentModule(), fileName, sizeof(fileName));
- 在DLL中如何确定自身的文件路径
- DLL中如何获取自身的路径
- DLL中如何获取自身的路径
- 在DLL中获取自身的路径
- 在VC中获取当前DLL自身的路径
- 如何获取DLL自身的路径
- dll中如何得到自身路径(指的是dll路径)
- DLL中如何获取自身的句柄
- DLL和EXE如何读取包含在自身的资源文件
- 详解在bash脚本中如何获取自身路径
- 详解在bash脚本中如何获取自身路径(转)
- 详解在bash脚本中如何获取自身路径
- C++在dll中获取自身路径(非exe调用路径)
- 在Dll中调用自身的位图资源
- 如何在VB中打开一个Excel文件并调用Excel文件自身的VBA宏?
- 在DLL中使用DLL自身资源时的问题及解决方案
- 如何在.Net的C#中制作DLL文件
- 如何在.Net的C#中制作DLL文件
- webwork 教程2
- webwork教程 3
- TDD——NUnit的原理
- Struts + WebWork = Struts Ti
- 导入导出命令
- 在DLL中如何确定自身的文件路径
- 常用的查询语句
- MX采取了防范措施之后
- 汽车配件公司业务系统设计报告
- Hibernate配置文件在单元测试中的灵活运用
- linux安装后的PQ分区表#114
- Red Hat Enterprise Linux AS 安装 Oracle 9i过程整理
- 快钱联手浩方 开拓网络游戏运营
- 当关闭子窗口时刷新父窗口