Click to See Complete Forum and Search --> : Help on pointers


kevinh
November 20th, 2001, 02:21 PM
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

Andreas Masur
November 20th, 2001, 06:17 PM
>> 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

kevinh
November 21st, 2001, 09:34 AM
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.

James Curran
November 21st, 2001, 11:32 AM
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.