Thinking and Researching

数字冰块的思考空间

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
用 Win32 API CreateFile 打开软驱并返回一个 Handle ,然后用这个 Handle 构造 .NET 的 FileStream 。代码如下:

IntPtr handle = CreateFile(
    "\\\\.\\A:",
    (uint)FileAccess.Write,
    (uint)FileShare.Write,
    0,
    (uint)FileMode.Open,
    0,
    0
    );
  
 FileStream fs 
= new FileStream(handle,FileAccess.Write);

运行便会在构造 FileStream 的时候发生异常:

未处理的异常: System.IO.IOException: 参数不正确。

   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream.get_Length()
   at System.IO.FileStream..ctor(IntPtr handle, FileAccess access, Boolean ownsH
andle, Int32 bufferSize, Boolean isAsync)
   at System.IO.FileStream..ctor(IntPtr handle, FileAccess access, Boolean ownsH
andle)

非常奇怪,有谁知道为什么吗?用类似的 CreateFile 构造 FileStream 访问其他文件(包括 FileStream 目前还不直接支持的 NTFS 命名流)都没问题的。
posted on 2004-07-29 22:49  数字冰块  阅读(1070)  评论(3编辑  收藏  举报