Link to home
Start Free TrialLog in
Avatar of pokrakam
pokrakamFlag for United Kingdom of Great Britain and Northern Ireland

asked on

NTFS file compression

I need to compress a file on an NTFS volume using NT's compression attributes. It can't be done by changing the compressed attribute (2048). I've found API calls CreateFile and DeviceIoControl can do the trick, but I cant get them to work correctly.
Avatar of MikeP090797
MikeP090797

Which one doesn't work?
Avatar of pokrakam

ASKER

I got this line of C code which apparently does the trick:
bRet = DeviceIoControl(hFile, FSCTL_SET_COMPRESSION, &uMode, sizeof(uMode), NULL, 0, &dwAttributes, NULL)
Can't getit to work with VB as:
nRet = DeviceIoControl(nHandle, &HD0003, nMode, 4&, 0&, 4&, 0&, 0&)
Tried various combinations of parameters.
Maybe just write a dll and call it from vb
That's not a very good answer - with a few rare exceptions if it can be done from a DLL it can be done from VB.

pokrakam, I just figured out how to do it - I'll post the code as soon as I can post it as an answer (i.e. as soon as you reject the current one). What you had is close, who knows, maybe by the time you read this you might have figured it out. (If so, please give me a chance to post the answer anyway and get the points, since I spent a lot of time figuring this one out). Thanks!
alamo's comment was about the most useful answer thus far, so I'll reopen the question.
ASKER CERTIFIED SOLUTION
Avatar of alamo
alamo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry about delay - 'puter got trashed, back online now.
All workes fine - I'd love to know where you got
FSCTL_SET_COMPRESSION As Long = &H9C040
from???

I computed FSCTL_SET_COMPRESSION from the header file definitions. I did however, compute it the first time incorrectly (as &HD0003, same as you). Having seen &HD0003 in your post I didn't question my initial computation and  wasted 2-3 hours trying things. Then I went back and double-checked and found that in:

#define CTL_CODE( DeviceType, Function, Method, Access )
(((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | Method))

the order of the arguments and the order they are used are different, the middle two are swapped. If you don't notice they are swapped you get &HD003. When you do eventually notice you get
the right answer... oh well.