The most elegant way to encapsulate WinAPI callbacks inside a class

Posted by FractalizeR on Stack Overflow See other posts from Stack Overflow or by FractalizeR
Published on 2010-06-01T20:26:46Z Indexed on 2010/06/01 21:23 UTC
Read the original article Hit count: 271

Filed under:
|
|

Hello.

I am thinking about elegant way to encapsulate WinAPI callbacks inside a class. Suppose I am making a class handling asynchronous I/O. All Windows callbacks should be stdcall functions, not class methods (I need to pass their addresses to ReadFileEx WinAPI function for example). So, I cannot just pass method addresses as a callback routines to WinAPI functions.

What is the most elegant way to encapsulate functionality of this type inside a class so that the class have events OnReadCompleted and OnWriteCompleted (I am using Delphi as a primary language, but I guess the situation must be the same in C++ because class methods are different from simple methods by the fact, that the first hidden parameter of them is this link. Of course this class is not a singleton and there can be many of them created by app at the same time.

What do you think would be the good way to implement this?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about winapi