简体   繁体   English

如何在Windows平台上使用C ++信号

[英]how to use c++ signals on windows platform

I know C on UNIX has signal() to call some function after some actions. 我知道UNIX上的C有signal()在执行某些操作后调用某些函数。 I need it on Windows. 我在Windows上需要它。 I have found, what it exists from here . 我发现, 这里存在着什么。 But I don't understand how to use it correctly. 但是我不明白如何正确使用它。

I tried it like in UNIX: 我在UNIX中尝试过:

signal(SIGINT, signalFunction);    //attach function to signal

void CRegBackupWiz::signalFunction(int sigNum)    //function
{
    m_Parent->SetWizard (swContinueFix);
}

I can't find, what is wrong with my code. 我找不到,我的代码有什么问题。 Thanks for advices, I appreciate that. 感谢您的建议,我对此表示赞赏。

Okay so you need to look at how to use function pointers, and in particular how to use pointers to member functions : http://www.parashift.com/c++-faq/pointers-to-members.html . 好的,因此您需要研究如何使用函数指针,尤其是如何使用指向成员函数的指针: http : //www.parashift.com/c++-faq/pointers-to-members.html

In general if you are using a pointer to a function as a callback mechanism you should use a top level free function (non-member) as a wrapper. 通常,如果您使用指向函数的指针作为回调机制,则应使用顶级自由函数(非成员)作为包装器。 See here: http://www.parashift.com/c++-faq/memfnptr-vs-fnptr.html 看到这里: http : //www.parashift.com/c++-faq/memfnptr-vs-fnptr.html

That code doesn't actually work under Unix either. 该代码实际上在Unix下也不起作用。

Pointers to members are different from ordinary pointers - you need to use either a free function or a static member function. 指向成员的指针与普通指针不同-您需要使用自由函数或静态成员函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM