Results 1 to 4 of 4

Thread: confused with Handle pointer

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    confused with Handle pointer

    Hi Folks

    Pointers in C is something I always end up confusing myself with...

    I have a function that is passed a pointer to a handle. this function should then pass that pointer on to a sub-function.
    Code:
    int txSerial (HANDLE *hComm) {
      // Do some stuff using *hComm here.
      // EG. 
      if (*hComm == INVALID_HANDLE_VALUE) {
        printf("Comm port returned an invalid handle\n");
        return 1;
      }
      return 0;
    }
    
    int txSPI (HANDLE *hComm) {
      return (txSerial(hComm));  //<<--- CONFUSED HERE.
    }
    
    int main (void) {
      HANDLE hComm1;
      int x;
      // Assign a handle to hComm1.
    
      x = txSPI(&hComm1);
      return x;
    }
    My confusion is where I call the sub-function txSerial().
    Should I be passing *hComm or hComm ???
    Got my thinking all knotted up here, help much appreciated, Thanks
    Last edited by wolf99; Jun 4th, 2011 at 07:47 AM.
    Thanks

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Re: confused with Handle pointer

    Im thinking it should be hComm not *hComm

    As to pass it *hComm would be to pass the data stored at the location pointed to by hComm (ie the HANDLE itself) rather than passing the address of that location....

    Is that correct or have I got it arse-ways?
    Thanks

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: confused with Handle pointer

    You're right.
    Since hComm in txSPI is already a pointer to a handle, you should pass it as-is to txSerial.

    *hComm would dereference the pointer, leaving you with the handle it points to.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Re: confused with Handle pointer

    Thanks Athiest
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width