开发者

Passing function pointers of class members

Service::serviceCtlHandler(DWORD OpCode)
{
  //...
}

Service::ServiceStart
{
  //...
  serviceStatusHandle = RegisterServiceCtrlHandler("Service", &Service开发者_JAVA百科::serviceCtrlHandler /*incompatible*/); 
  //...
}

How do I get a compatible pointer?


You'll need to make your serviceCtlHandler function static, which means it won't be able to access any object members. This is because RegisterServiceCtrlHandler is expecting a function pointer which is not tied to an object and will not receive an implied this pointer.

If you use RegisterServiceCtrlHandlerEx instead, you can pass a pointer to the object and have the static function call another member function after properly casting the pointer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜