I was wondering if there was anyway to use functions like ReadFileEx
that require a pointer to a function in a class WITHOUT marking the function as static? Thanks in advance. SBP.
views:
57answers:
2
+1
A:
No, non-static class functions have an implied first argument (this) which is incompatible with their use as a callback for ReadFileEx etc.
John Knoeller
2010-03-19 02:33:42
That's the answer I was looking for, thanks.
2010-03-19 02:46:33
A:
You can always extend the OVERLAPPED struct that you pass to include a pointer to your object. Then, pass a function that calls a member function on that object. Somewhat like this:
typedef struct _MYOVERLAPPED
{
OVERLAPPED ol;
MyObject *obj;
} MYOVERLAPPED, *LPMYOVERLAPPED;
void ReadCompleted(DWORD err, DWORD read, LPMYOVERLAPPED overlap)
{
overlap->obj->foo();
}
Sorry if there's some slight syntax errors in above code, it's been a while since I actually wrote some C++...
Kosta
2010-06-08 07:44:24