PowerRegisterSuspendResumeNotification - 提供的回调函数不能按预期工作 [英] PowerRegisterSuspendResumeNotification - provided callback function doesn't work as expected

查看:511
本文介绍了PowerRegisterSuspendResumeNotification - 提供的回调函数不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我注册我的应用程序,以便在系统暂停或恢复时接收通知。  MSDN
文档


函数我希望在应用程序收到通知后执行(我尝试了void和void CALLBACK并且两者都工作方式相同):

Function I'd like to be executed after application receives notification (I tried both void and void CALLBACK and both work same way):

void isConnectedStandby()
{
    printf( "ConnectedStandby Request");
}



第一种情况 - 我提供指向isConnectedStandby函数的指针,但系统将其视为指向函数的双指针 - 它调用此回调指针下的地址。

1st case - I provide pointer to the isConnectedStandby function, but system treats as a double pointer to the function - it calls an address which is under this callback pointer.

HPOWERNOTIFY RegistrationHandle;

PowerRegisterSuspendResumeNotification(
      DEVICE_NOTIFY_CALLBACK,
      &isConnectedStandby,
      &RegistrationHandle
);



第二种情况 - 这里我提供如下(这样我的函数代码被执行):

2nd case - here I provide as follows (this way my function code is executed):

typedef void (*StatusFunction_t)(); 
StatusFunction_t StatusFunction = isConnectedStandby;
HPOWERNOTIFY RegistrationHandle;

    PowerRegisterSuspendResumeNotification(
      DEVICE_NOTIFY_CALLBACK,
      &isConnectedStandby,
      &RegistrationHandle
);



系统调用不仅是我的函数,而是第一个之后的所有地址(如果我提供了一个函数数组,它会在没有有效代码时一个接一个地执行崩溃)

System calls not only mine function, but all addresses after the first one (if I provide an array of functions, it executes one after another to crash when there is no valid code available)


使用这个函数的正确方法是什么?

What is the correct way to use this function?

推荐答案

哇,我不喜欢知道我是否看过比 $ b更糟糕的文档这里是$ b。 它说它需要一个回调函数,但是将参数的类型列为HANDLE,并且不提供任何关于函数签名应该是什么的文档。

Wow, I don't know if I have seen worse docs than are here.  It says it takes a callback function, but lists the type of the parameter as a HANDLE, and doesn't give any sort of documentation on what the signature of the function should be.

既然您说第二个版本有效,您是否尝试过创建一个函数指针数组并将其终止? (注意:我绝对不会从文档中猜出这个用法,但这是我唯一的猜测。

Since you say that the second version works, have you tried creating an array of function pointers and null terminating it?  (Note: that I would never guess that usage at all from the docs, but it is the only guess I have).

如果这不起作用,老实说我不确定你在哪里提出修复文档的请求。 也许作为社区内容在该页面上。

If that doesn't work, I am honestly not sure where you put in a request to fix the documentation.  Perhaps as community content on that page.


这篇关于PowerRegisterSuspendResumeNotification - 提供的回调函数不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆