Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with FileIOCompletionRoutine ???

Problem with FileIOCompletionRoutine ???

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HumanOsc
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • H HumanOsc

      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

      C Offline
      C Offline
      cmk
      wrote on last edited by
      #2

      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

      H 1 Reply Last reply
      0
      • C cmk

        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

        H Offline
        H Offline
        HumanOsc
        wrote on last edited by
        #3

        Hello... This is very guru like solution... :) Big Thx, greets from germany...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups