dll路径更改跟Xp系统属性设置有关吗?

water1225 2011-04-29 09:23:36
PS:我程序中创建一个目录test,在该目录下面放程序要用到的所有dll,当程序loaddll时,把路径指向test,加载完成后我再把工作路径还原.
现在的问题时:几台测试机exe放在test(test中为exe加载的所有dll)外面时,可以正常运行exe;
但是有一台机子如上放置时exe不能运行,找不到dll路径,把exe放到test目录中跟dll一起时便能正常运行?

这是什么原因啊?是不是系统设置项会导致路径指向不正确? 怎么设置系统才能使其路径指向正确呢?
...全文
89 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
老邓 2011-04-29
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wish_cn 的回复:]

The search path can be altered using the SetDllDirectory function. This solution is recommended instead of using SetCurrentDirectory or hard-coding the full path to the DLL.


BOOL SetDllDirectory……
[/Quote]
第一次看到这个API,不错!!
water1225 2011-04-29
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 loaden 的回复:]
http://msdn.microsoft.com/en-us/library/ms683197%28v=vs.85%29.aspx
通过GetModuleFileName 获取EXE的完整路径,之后调整一下。
否则问题多多!
[/Quote]

先GetModuleFileName获取完整路径
然后在该路径下建一个test文件夹得,再把路径指向该test文件夹,加载动态文件后,再指回原来工作路径的
water1225 2011-04-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 newstudent_never 的回复:]
不是,, 放在system32下面也可以找到。。

其它地方就不行了。。。 你想 f盘放一个dll, 在c盘中启动exe, 谁能知道你要加载的dll在哪里啊?
[/Quote]

是先获取exe路径的
wish_cn 2011-04-29
  • 打赏
  • 举报
回复
The search path can be altered using the SetDllDirectory function. This solution is recommended instead of using SetCurrentDirectory or hard-coding the full path to the DLL.


BOOL SetDllDirectory(
LPCTSTR lpPathName
);


The SetDllDirectory function affects all subsequent calls to the LoadLibrary and LoadLibraryEx functions. After calling SetDllDirectory, the DLL search path is:

The directory from which the application loaded.
The directory specified by the lpPathName parameter.
The system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is System32.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The directories that are listed in the PATH environment variable.
water1225 2011-04-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 newstudent_never 的回复:]
不是,, 放在system32下面也可以找到。。

其它地方就不行了。。。 你想 f盘放一个dll, 在c盘中启动exe, 谁能知道你要加载的dll在哪里啊?
[/Quote]

exe 和放dll 的文件夹在同一个目录下面
老邓 2011-04-29
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/en-us/library/ms683197%28v=vs.85%29.aspx
通过GetModuleFileName 获取EXE的完整路径,之后调整一下。
否则问题多多!
老邓 2011-04-29
  • 打赏
  • 举报
回复
加载DLL模块,应该都使用绝对路径,而不是相对路径!!
就想叫yoko 2011-04-29
  • 打赏
  • 举报
回复
WINDOWS核心编程
19章第五节
luciferisnotsatan 2011-04-29
  • 打赏
  • 举报
回复
环境变量设置的关系?
看看PATH里有没有test外那个目录
ouyh12345 2011-04-29
  • 打赏
  • 举报
回复
环境变量会发生改变的
先获得exe的路径,然后再去找dll的路径
xmu_才盛 2011-04-29
  • 打赏
  • 举报
回复
不是,, 放在system32下面也可以找到。。

其它地方就不行了。。。 你想 f盘放一个dll, 在c盘中启动exe, 谁能知道你要加载的dll在哪里啊?

69,380

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧