Problem with FileIOCompletionRoutine ???
-
-
Hello... I like to implement WriteFileEx / ReadFileEx in one of my classes... Is there any safe way to implement LPOVERLAPPED_COMPLETION_ROUTINE as a (non static) member function ? :doh: Thx... :-D -- modified at 5:09 Wednesday 14th September, 2005
Off the top of my head (i.e. untested) do something like this:
#define IOOP_READ 1
#define IOOP_WRITE 2#define CK_CONTAINING_RECORD( PTR, TYP, FLD ) \
( (TYP*)( (byte*)(PTR) - (byte*)(&((TYP*)0)->FLD) ) )class MyFile; // forward reference
class MyOL : public OVERLAPPED {
public:
virtual ~MyOL( void ) {
if( Buff ) delete [] Buff;
}MyFile \*File; DWORD Op; DWORD Cnt; char \*Buff; // go around vtable OVERLAPPED Ptr( void ) { return(&Internal); }
};
class MyFile {
protected:
HANDLE hnd;static void CALLBACK iocr( DWORD ERR, DWORD CNT, OVERLAPPED \*OL ) { if( !OL ) return; MyOL \*ol = CK\_CONTAINING\_RECORD(OL, MyOL, Internal); ol->Cnt = CNT; ol->File->OnIOC(ol); delete ol; } void onIOC( MyOL \*OL ) { switch( OL->Op ) { case IOOP\_READ : ... case IOOP\_WRITE : ... } }
public:
bool ReadEx( DWORD SZ ) {
if( !SZ ) return(false);
MyOL *ol = new MyOL();
ol->Op = IOOP_READ;
ol->File = this;
ol->Buff = new char[SZ];
return( ReadFileEx(hnd, ol->Buff, SZ, ol->Ptr(), iocr) );
}
bool WriteEx( DWORD SZ, void *BUFF ) {
if( !SZ || !BUFF ) return(false);
MyOL *ol = new MyOL();
ol->Op = IOOP_WRITE;
ol->File = this;
ol->Buff = new char[SZ];
memcpy(ol->Buff, BUFF, SZ);
return( WriteFileEx(hnd, ol->Buff, SZ, ol->Ptr(), iocr) );
}
};...cmk Save the whales - collect the whole set
-
Off the top of my head (i.e. untested) do something like this:
#define IOOP_READ 1
#define IOOP_WRITE 2#define CK_CONTAINING_RECORD( PTR, TYP, FLD ) \
( (TYP*)( (byte*)(PTR) - (byte*)(&((TYP*)0)->FLD) ) )class MyFile; // forward reference
class MyOL : public OVERLAPPED {
public:
virtual ~MyOL( void ) {
if( Buff ) delete [] Buff;
}MyFile \*File; DWORD Op; DWORD Cnt; char \*Buff; // go around vtable OVERLAPPED Ptr( void ) { return(&Internal); }
};
class MyFile {
protected:
HANDLE hnd;static void CALLBACK iocr( DWORD ERR, DWORD CNT, OVERLAPPED \*OL ) { if( !OL ) return; MyOL \*ol = CK\_CONTAINING\_RECORD(OL, MyOL, Internal); ol->Cnt = CNT; ol->File->OnIOC(ol); delete ol; } void onIOC( MyOL \*OL ) { switch( OL->Op ) { case IOOP\_READ : ... case IOOP\_WRITE : ... } }
public:
bool ReadEx( DWORD SZ ) {
if( !SZ ) return(false);
MyOL *ol = new MyOL();
ol->Op = IOOP_READ;
ol->File = this;
ol->Buff = new char[SZ];
return( ReadFileEx(hnd, ol->Buff, SZ, ol->Ptr(), iocr) );
}
bool WriteEx( DWORD SZ, void *BUFF ) {
if( !SZ || !BUFF ) return(false);
MyOL *ol = new MyOL();
ol->Op = IOOP_WRITE;
ol->File = this;
ol->Buff = new char[SZ];
memcpy(ol->Buff, BUFF, SZ);
return( WriteFileEx(hnd, ol->Buff, SZ, ol->Ptr(), iocr) );
}
};...cmk Save the whales - collect the whole set