[quote]
I was able to make it work. The problem was that for some reason when the driver
is UMDF (and this is 2.15) DECLARE_UNICODE_STRING_SIZE was not setting the
length of i2cPath UNICODE_STRING and was always 0.
[quote]
To follow-up Mr. Rajeev’s note: He’s (of course) exactly correct. DECLARE_UNICODE_STRING_SIZE allocates the space for, declares the UNICODE_STRING structure, and sets the Buffer and MaximumLength fields of the structure. It’s not SUPPOSED to set the length. How could it? The string hasn’t been placed into the Buffer yet!!
Soooo… you might ask, in the programming pattern:
[>>>INCORRECT CODE FOLLOWS<<<]
DECLARE_UNICODE_STRING_SIZE(i2cPath, RESOURCE_HUB_PATH_SIZE);
RESOURCE_HUB_CREATE_PATH_FROM_ID(
&i2cPath,
pDevice->PeripheralId.LowPart,
pDevice->PeripheralId.HighPart);
It’s the call RESOURCE_HUB_CREATE_PATH_FROM_ID that builds the string and sets the length member of the UNICODE_STRING.
So, why didn’t that work in your case??
Because apparently you’re not checking the return status from RESOURCE_HUB_CREATE_PATH_FROM_ID. Which, I bet, is failing.
Your code should look like the following:
[>>>CORRECTED CODE FOLLOWS<<<]
DECLARE_UNICODE_STRING_SIZE(i2cPath, RESOURCE_HUB_PATH_SIZE);
status = RESOURCE_HUB_CREATE_PATH_FROM_ID(
&i2cPath,
pDevice->PeripheralId.LowPart,
pDevice->PeripheralId.HighPart);
if(!NT_SUCCESS(status)) {
… do something … log something …
return;
}
Remember, Mr. Tripathi… Don’t stop working on an issue as soon as you find *a* fix that will fix the symptoms of your bug. Really try to discover what the root cause the problem. Given that there are MANY WDK sample drivers that use the programming pattern you’ve used, and that DECLARE_UNICODE_STRING_SIZE isn’t new, it’s *very* unlikely that there’s a bug in that macro or in the pattern that’s being illustrated.
Soooo… it *real* bug must lie somewhere else.
Continue to search. Solving problems at the root cause whenever possible (sometimes it is not politically possible or practical to do this, it’s also important to recognize when that’s the case), and not merely eliminating symptoms, will make you a strong engineer that everyone will want to work with.
Peter
OSR
@OSRDrivers