分享

OpenFile 和 CreateFile 的区别

 戴维图书馆 2014-05-07
偶然被人问到OpenFile和CreateFile路径的问题,查了MSDN,然后做了一下Debug,记录一下心得
首先OpenFile是一个16-bit windows 的函数,现在再写新的程序应该用CreateFile来代替。
有一些老的code可能还是用的OpenFile来打开文件,如果现在升级到CreateFile,就需要注意路径的问题了。
OpenFile 可以只给一个文件名称,然后会有相应的路径搜索顺序:
  1. The directory where an application is loaded.

  2. The current directory.

  3. The Windows system directory.

  4. The 16-bit Windows system directory.

    There is not a function that retrieves the path of this directory, but it is searched.

  5. The Windows directory.

  6. The directories that are listed in the PATH environment variable.

在kernel32!openFile里面会调用到kernel32!SearchPath 函数来查找,这个行为是和loadlibrary一致的。
比如在c:\windows\system32下面有一个sicl32.dll的文件
如果用OpenFile("sicl32.dll"....)是可以打开成功的,因为里面会搜索到c:\windows\system32目录
但是用CreateFile("sicl32.dll"...)会失败,必须以“c:\\windows\\system32\sicl32.dll”为参数才能成功。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多