문제

I have my own overlapped structure for asynchronous IO using IO Completion ports.

Now i get notification for read / write completions. Can i pass a CALLBACK function as a parameter in the overlapped structure?

This will allow me to specify various callback functions based on the type of overlapped structure i passed

Has anybody had any luck with this?

도움이 되었습니까?

해결책

Create you own structure derived from OVERLAPPED:

struct MyOverlapped : OVERLAPPED
{
  CALLBACK MyCallback;
};

Now use this instead:

MyOverlapped *o=new MyOverlapped;
o->MyCallback=CallbackHandler;

WriteFile(..,..,MyOverlapped);

Then when you get the OVERLAPPED back you can cast it to your derived version:

MyOverlapped *o=static_cast<MyOverlapped*>(overlapped);

And now you can access the callback. I'm guessing you're getting the OVERLAPPED instance back from a call to GetQueuedCompletionStatus where the pointer you get back will actually point to your derived structure.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top