mardi 5 octobre 2021

Using an intermediary function to direct a callback to a member function

I believe this question resembles this question. However I am not sure how to adjust that to my case. Here is what I am doing.

I currently have something like this

void IOCompletionCallback(_In_ DWORD dwErrorCode, _In_ DWORD dwNumberOfBytesTransfered, _Inout_ LPOVERLAPPED lpOverlapped)
{
   ......    
}

void foo::Work()
{
     if (!BindIoCompletionCallback(hnd, IOCompletionCallback, 0))
     {
          printf("Error (error code: %u)\n", GetLastError());
     }
}

In the above code I am using the windows API BindIoCompletionCallback which takes in the function IOCompletionCallback. What I would like to do is to actually make IOCompletionCallback a method of foo instead of a free function so I could do this

if (!BindIoCompletionCallback(hnd, std::bind( &foo::IOCompletionCallback,this), 0))
{
}

but I read that is impossible because signature of the method takes in a specific type. From the link I posted that it states that you can use an intermediary method. I am not sure how Ill be able to pass the instance address to that intermediary method. Any suggestions on that approach would be appreciated.

Aucun commentaire:

Enregistrer un commentaire