-
April 16th, 2010, 03:36 AM
#1
WriteFile writes zero's instead of my bytes
Code in C++:
short buffer[6];
buffer[0] = 1;
buffer[1] = 2;
buffer[2] = 3;
buffer[3] = 4;
buffer[4] = 5;
buffer[5] = 6;
short *p = &buffer[0];
int bufflen = 6;
int ret;
WriteFile(g_handle, p, bufflen, &ret, NULL);
After executing ret = 6 and WriteFile is a success. But when i open file with hex editor i see this:
01 00 02 00 03 00
So basically WriteFile wrote my byte then zero, then my byte, then zero again. Is this bug? Or i am doing something wrong? Thanks for help.
-
April 16th, 2010, 03:40 AM
#2
Re: WriteFile writes zero's instead of my bytes
Originally Posted by Vila
Code in C++:
int bufflen = 6;
int ret;
WriteFile(g_handle, p, bufflen, &ret, NULL);
If I call with bufflen = 12 then ret = 12 and in file:
01 00 02 00 03 00 04 00 05 00 06 00.
This is confusing...
-
April 16th, 2010, 03:51 AM
#3
Re: WriteFile writes zero's instead of my bytes
I thought that short is 8bit unsigned integer, and it turns out it is 16bit integer. Sorry about that. Will use unsigned char.
-
April 16th, 2010, 03:53 AM
#4
Re: WriteFile writes zero's instead of my bytes
Seems pretty normal to me. You should use:
Code:
WriteFile(g_handle, p, sizeof(buffer), &ret, NULL);
Each 'short' that you write puts two bytes in the file, the low byte followed by the high byte.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|