[Win32utils-devel] Problems with DeviceIoControl()

win32utils-devel at rubyforge.org win32utils-devel at rubyforge.org
Mon Nov 8 03:00:01 EST 2004


Hi,
> 
> Hi all,
> 
> Thanks to Wayne and Park, I've got something like this
> now:
> 
..
> 
> But, I'm still getting "access denied" or "invalid
> access to memory location", depending on the open mode
> flag I use.
> 
> Testing indicates that I am getting a valid HANDLE,
> but that DeviceIoControl() is failing.  I can,
> however, compress the file using the GUI interface.
> 
> Any ideas?
> 
> Wayne, I saw your note on using _fileno, but I don't
> think I need it here, do I?
> 
 
You have missed & before inBuf.

Here is my modified version:
---------------------------------------------------------------
static VALUE file_set_compressed(VALUE self, VALUE rbBool){
   HANDLE h;
   BOOL rv;
   DWORD dwBytesReturned;
   int fn;
   VALUE rbPath;
   USHORT inBuf = COMPRESSION_FORMAT_DEFAULT;

   if((rbBool != Qtrue) && (rbBool != Qfalse)){
      rb_raise(rb_eTypeError,"Argument must be true or false");
   }

   if(rbBool == Qfalse){
      inBuf = COMPRESSION_FORMAT_NONE;
   }

   rbPath = rb_funcall(self,rb_intern("path"),0,0);

   h = CreateFile(
                StringValuePtr(rbPath),
                FILE_READ_DATA | FILE_WRITE_DATA,
                FILE_SHARE_READ | FILE_SHARE_WRITE,
                NULL,
                OPEN_EXISTING,
                0,
                NULL
                );

   rv = DeviceIoControl(
      h,
      FSCTL_SET_COMPRESSION,
      (LPVOID)&inBuf,
      sizeof(inBuf),
      NULL,
      0,
      &dwBytesReturned,
      NULL
   );

   CloseHandle( h );

   if(!rv){
      rb_raise(cFileError,ErrorDescription(GetLastError()));
   }

   return self;
}
----------------------------------------------------------------
Regards,

Park Heesob




--MIME Multi-part separator--



More information about the win32utils-devel mailing list