> Hi,
I am working on a minifilter and it works without problems so far when I
let it auto-attach to all volumes after successfully loading it. I have
disabled the auto-attach behavior now and instead want to attach my
minifilter from an own user space control daemon that is calling
FilterAttach(). However, every time I get an error code of 0x80070002 as a
result.
Here is the relevant code:
HRESULT status;
TCHAR lpDosName[100];
DO NOT use Hungarian Notation unless you use it correctly. DosName is NOT
an “lp”, it is an actual character array, not a variable which is a
pointer to a character array. Te problem is, if you use it, someone who
is reading the code will assume that you are using it correctly.
status = FilterGetDosName(argv[2], lpDosName, 100);
if (status == S_OK)
{
printf(“Received the following dos name for volume ‘%ls’: %ls\n”,
argv[2], lpDosName);
You have a very odd mix of 8-bit and 16-bit characters, which is a
long-term recipe for total disaster. Why 100? That’s a pretty
meaningless random number. Why not MAX_PATH?
Does FilterGetDosName require a wide-character buffer? If so, your buffer
must not be TCHAR, it must be WCHAR, which is always wide-character
independent of the compilation mode. If you compile this in 8-bit mode,
your call specifies a buffer of 100 characters, but in 8-bit compilations,
TCHAR==char, so you’ve told it the buffer is twice as big as it actually
is. Your code will work for a while. If it is a byte count, then you
should be using sizeof; if it is a character count, then it will be
sizeof(DosName)/sizeof(TCHAR) or, if DosName is WCHAR it will be
sizeof(DosName)/sizeof(WCHAR). If the value returned is always WCHAR, and
the size is bytes, then sizeof(DosName) will becorrect. If the value is
TCHAR, then in an 8-bit compiation the call will return 8-bit characters,
and %ls will be incorrect.
Use _tprintf, which takes a WCHAR formatting string.
If this will run as a service, you really can’t use printf, because there
will be no console to write to.
}
else
{
printf(“Operation failed with error 0x%08lx\n”, status);
}
status = FilterAttach(L"myminifilter",
argv[2],
argv[2],
NULL,
NULL);
The filter is successfully loaded using the OpenSCManager() and
OpenService() approach, and the application is executed in a terminal
running as administrator. fltmc shows that the filter is loaded and has 0
instances.
When I run my application with “C:” as argv[2] then, I get the following
output:
Received the following dos name for volume ‘C:’: C:
Error code: 0x80070002
However, when I attach the filter to “C:” using fltmc everything works
fine… What is my mistake? Insufficient access rights? According to the
Microsoft Error Code tool 0x80070002 refers to an object or file not found
error, which is strange because FilterGetDosName(…) can handle the input
“C:”. I also tried other inputs for argv[2], but no success.
In case it matters: my target platform is Win 8.1 32-bit in a virtual
machine.
Thanks for your help
Jens
NTFSD is sponsored by OSR
OSR is hiring!! Info at http://www.osr.com/careers
For our schedule of debugging and file system seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer