mirror of
https://github.com/nefarius/WDF-Utils.git
synced 2024-11-23 23:44:54 +01:00
Added RegisterPowerStateChangeCallback
This commit is contained in:
parent
983423bcce
commit
d864b69334
60
Snippets/WDM/RegisterPowerStateChangeCallback.md
Normal file
60
Snippets/WDM/RegisterPowerStateChangeCallback.md
Normal file
@ -0,0 +1,60 @@
|
||||
# RegisterPowerStateChangeCallback
|
||||
|
||||
```c
|
||||
NTSTATUS RegisterPowerStateChangeCallback(_Inout_ DEVICE_EXTENSION* pDeviceExtension)
|
||||
{
|
||||
#if DBG
|
||||
|
||||
DbgPrintEx(DPFLTR_IHVNETWORK_ID,
|
||||
DPFLTR_INFO_LEVEL,
|
||||
" ---> RegisterPowerStateChangeCallback()\n");
|
||||
|
||||
#endif /// DBG
|
||||
|
||||
NT_ASSERT(pDeviceExtension);
|
||||
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
OBJECT_ATTRIBUTES objectAttributes = {0};
|
||||
UNICODE_STRING unicodeString = {0};
|
||||
|
||||
RtlInitUnicodeString(&unicodeString,
|
||||
L"\\Callback\\PowerState");
|
||||
|
||||
InitializeObjectAttributes(&objectAttributes,
|
||||
&unicodeString,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
0,
|
||||
0);
|
||||
|
||||
status = ExCreateCallback(&(pDeviceExtension->pCallbackObject),
|
||||
&objectAttributes,
|
||||
FALSE, /// Do not create as the system should already have done this
|
||||
TRUE); /// Allow multiple callbacks
|
||||
if(status != STATUS_SUCCESS)
|
||||
{
|
||||
DbgPrintEx(DPFLTR_IHVNETWORK_ID,
|
||||
DPFLTR_ERROR_LEVEL,
|
||||
" !!!! RegisterPowerStateChangeCallback : ExCreateCallback() [status: %#x]\n",
|
||||
status);
|
||||
|
||||
HLPR_BAIL;
|
||||
}
|
||||
|
||||
pDeviceExtension->pRegistration = ExRegisterCallback(pDeviceExtension->pCallbackObject,
|
||||
PowerStateCallback,
|
||||
pDeviceExtension);
|
||||
|
||||
HLPR_BAIL_LABEL:
|
||||
|
||||
#if DBG
|
||||
|
||||
DbgPrintEx(DPFLTR_IHVNETWORK_ID,
|
||||
DPFLTR_INFO_LEVEL,
|
||||
" <--- RegisterPowerStateChangeCallback() [status: %#x]\n",
|
||||
status);
|
||||
|
||||
#endif /// DBG
|
||||
|
||||
return status;
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user