BindIoCompletionCallback in a class, problem with LPOVERLAPPED_COMPLETION_ROUTINE
-
Hello I want to create a baseclass for socket servers that use io completion ports. But I cant manage to pass a class function to BindIoCompletionCallback. BOOL BindIoCompletionCallback( HANDLE FileHandle, LPOVERLAPPED_COMPLETION_ROUTINE Function, ULONG Flags ); I call it with: BindIoCompletionCallback((HANDLE)m_sdListen, DoneIO, 0); My class looks like: class IocpServer { public: IocpServer(void); ~IocpServer(void); void CreateListenSocket(int ListenPort); void Start(void); HANDLE GetDieEvent(); void CALLBACK DoneIO(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped); private: SOCKET m_sdListen; DWORD m_dwThreadCount; HANDLE m_hIOCP; UINT m_iListenPort; HANDLE m_hDieEvent; }; I get this error: d:\projects\cpp\Datatal\HvdServer\IocpServer.cpp(24) : error C2664: 'BindIoCompletionCallback' : cannot convert parameter 2 from 'void (DWORD,DWORD,LPOVERLAPPED)' to 'LPOVERLAPPED_COMPLETION_ROUTINE' None of the functions with this name in scope match the target type
-
Hello I want to create a baseclass for socket servers that use io completion ports. But I cant manage to pass a class function to BindIoCompletionCallback. BOOL BindIoCompletionCallback( HANDLE FileHandle, LPOVERLAPPED_COMPLETION_ROUTINE Function, ULONG Flags ); I call it with: BindIoCompletionCallback((HANDLE)m_sdListen, DoneIO, 0); My class looks like: class IocpServer { public: IocpServer(void); ~IocpServer(void); void CreateListenSocket(int ListenPort); void Start(void); HANDLE GetDieEvent(); void CALLBACK DoneIO(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped); private: SOCKET m_sdListen; DWORD m_dwThreadCount; HANDLE m_hIOCP; UINT m_iListenPort; HANDLE m_hDieEvent; }; I get this error: d:\projects\cpp\Datatal\HvdServer\IocpServer.cpp(24) : error C2664: 'BindIoCompletionCallback' : cannot convert parameter 2 from 'void (DWORD,DWORD,LPOVERLAPPED)' to 'LPOVERLAPPED_COMPLETION_ROUTINE' None of the functions with this name in scope match the target type
I guess, that if the DoneIO is the member of your class, you can't do it in that way. The DoneIO can be a member only if it is a static member, then you can use it for callbacks. Normal class members have calling convention _thiscall, which you cannot achieve in callbacks. So for you it will help to make that function static (static members do not have the first hidden parameter - this).