开发者

Passing function pointers of class members

开发者 https://www.devze.com 2023-04-06 11:01 出处:网络
Service::serviceCtlHandler(DWORD OpCode) { //... } Service::ServiceStart { //... serviceStatusHandle = RegisterServiceCtrlHandler(\"Service\", &Service开发者_JAVA百科::serviceCtrlHandler /*incomp
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

精彩评论

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