[Win32utils-devel] Problems with DeviceIoControl()

win32utils-devel at rubyforge.org win32utils-devel at rubyforge.org
Sun Nov 7 11:09:50 EST 2004


Hi all,

Thanks to Wayne and Park, I've got something like this
now:

static VALUE file_set_compressed(VALUE self, VALUE
rbBool){
   HANDLE h;
   BOOL rv;   
   DWORD dwBytesReturned;
   int fn;
   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;
   }
   
   fn =
NUM2INT(rb_funcall(self,rb_intern("fileno"),0,0));
   h = (HANDLE)_get_osfhandle(fn); // Get HANDLE based
on fileno
   
   if(h == INVALID_HANDLE_VALUE){
     
rb_raise(cFileError,ErrorDescription(GetLastError()));
   }

   rv = DeviceIoControl(
      h,
      FSCTL_SET_COMPRESSION,
      (LPVOID)inBuf,
      sizeof(inBuf),
      NULL,
      0,
      &dwBytesReturned,
      NULL
   );
   
   if(!rv){   
  
rb_raise(cFileError,ErrorDescription(GetLastError()));
   }

   return self; 
}

// Inside Init_file()
rb_define_method(rb_cFile,"compressed=",file_set_compressed,1);

# Sample program
f = File.open("temp.txt")
f.compressed = true
f.close

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?

Regards,

Dan


		
__________________________________ 
Do you Yahoo!? 
Check out the new Yahoo! Front Page. 
www.yahoo.com 
 



More information about the win32utils-devel mailing list