I am playing with lambda in Visual C++ 11.
void CWin32Service::RunService (__in DWORD dwArgc, __in LPTSTR *lpszArgv)
{
auto SvcMainptr = [this](__in DWORD dwArgc, __in LPTSTR *lpszArgv) -> void {ServiceMain( dwArgc, lpszArgv );} ;
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ m_ServiceName, (LPSERVICE_MAIN_FUNCTION)SvcMainptr }, <<== Error HERE
{ NULL, NULL }
};
....
}
The error message I get is:
‘type cast’ : cannot convert from ‘CWin32Service::RunService::<lambda_22F3FB7B8C044A64>’ to ‘LPSERVICE_MAIN_FUNCTIONW’
That is a Win32 API that expects to take a real function pointer with an exact signature. You can’t pass a lambda or other type of function object to it.
You should be passing ServiceMain in the service dispatch table.