CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2001
    Location
    ny
    Posts
    3

    Help on pointers

    I have the following :

    BOOL rc = DeviceIoControl(hVxd, ioctl_code, (char*)&cmdBuf,
    count, (char*)&replyBuf, sizeof(replyBuf),
    &bytesReturned, NULL);

    My question is, cmdBuf is returned as a pointer. How can I assign a variable to this returned data so that I can do some manipulation. What I have been trying is :

    *somepointer = cmdBuf[i];
    or
    somearray[8] = cmdBuf[i];

    but the compiler complains. What am I doing wrong? I know it should be simple
    but I am lost.

    Thanks


  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Help on pointers

    >> My question is, cmdBuf is returned as a pointer.

    Well that is not right. The third parameter of this function is a 'void' pointer to a buffer that contains the data required to perform the operation. This parameter can be NULL if the control code parameter specifies an operation that does not require input data.

    'replybuf' is the pointer to a buffer that receives the operation's output data. This parameter can be NULL if the control code parameter specifies an operation that does not produce output data.

    So that would mean...

    int main()
    {
    char InputBuffer[100];
    char OutputBuffer[100];

    memset(InputBuffer, 0, sizeof(InputBuffer));
    memset(OutputBuffer, 0, sizeof(OutputBuffer));

    BOOL rc = DeviceIoControl(hVxd, // Device handle
    ioctl_code, // Operation control code
    InputBuffer, // Input buffer
    sizeof(InputBuffer), // Size of input buffer
    OutputBuffer, // Output buffer
    sizeof(OutputBuffer), // Size of output buffer
    &bytesReturned, // Returned bytes
    NULL); // Overlapped information
    }



    As you can see you need to allocate memory for both buffers before you call the function. Therefore you will already have a variable assigned to both buffers. The variable 'count' that you passed as the fourth argument needs to be the size of the input buffer.

    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds

  3. #3
    Join Date
    Nov 2001
    Location
    ny
    Posts
    3

    Re: Help on pointers

    Andreas Thanks for the help, perhaps I should
    have beenmore clear. I have allocated memory as you said:

    const unsigned maxBufSize = 256;
    unsigned char cmdBuf[maxBufSize];
    unsigned char replyBuf[maxBufSize];
    then :

    BOOL rc = DeviceIoControl(hVxd, ioctl_code, (char*)&cmdBuf,
    count, (char*)&replyBuf, sizeof(replyBuf),
    &bytesReturned, NULL);



    All is well if I just print out the the contents of the buffer upon return of the call such as :

    for(int i=0 i < maxBufsize;i++){
    cout << replyBuf(i);
    }




    and my data prints out. I however would like to
    do some bitwise manipulation on one of the bytes
    returned (lets just say the first returned byte)
    When I try assigning something is when I get compiler errors. I would really like to assign it to a string or an array in hopes I can modify the
    data such as :

    unsigned char status[8];

    *status = replyBuf[1];




    I have tried everything in my very novice arsenal
    to be able to assign one of these returned bytes from this replyBuf to a variable
    that I can manipulate, to no success. Sorry for
    the long reply, I just want to be as clear as
    possible.




  4. #4
    Join Date
    Sep 1999
    Location
    NJ
    Posts
    1,299

    Re: Help on pointers

    unsigned char status[8];
    *status = replyBuf[1];

    Status should be a char, not a char array, so it should be just:unsigned char status;
    status = replyBuf[1];




    Truth,
    James
    http://www.NJTheater.com
    http://www.NovelTheory.com
    I don't do it for the points (OK, maybe I do), but rating a post is a good way for me to know if I helped.

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

Featured