ckerneldriverdevice-driver

How clear flag in DEVICE OBJECT


Are these two Code equal?(clear flag)

ClearFlag(NewDeviceObject->Flags, DO_DEVICE_INITIALIZING);

NewDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

Solution

  • Yes they are equal.

    Unlike APIs, ClearFlag is a macro. You can enter the ntifs.h that you compile with and see it. Microsoft doesn't change macros like this, because then you won't be able to use the same binary on any older windows (which is not something they like). This is why only small utilities like that are inlined.

    Anyway it's a much better practice and much cleaner to use the macro, so use it like you use other win macro that won't be changed for same reasons (it's just not a bug not using it).