Re: Is this impossible ? ReadFile

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Ravi Ambros Wallau (nospam_at_nospam.com)
Date: 01/03/05


Date: Mon, 3 Jan 2005 08:42:21 -0300

Just another comment, the code that "works" doesn't "works", you're reading
the value from the file to some "obscure" location - you're passing the
address of the pointer that contains the address of the buffer, not the
address of the buffer it self.
Instead of ReadFile(..., (void*)&test...) you should use ReadFile(...,
test...). The cast to void* is useless, the compiler will really not care
about this.
I agree with hans, I always declare a struct like this:
typedef struct ST_TEST {
   int a, b;
} TEST;
TEST test;

-- 
Ravi Ambros Wallau
r w a l l a u @ s p r i n g w i r e l e s s . n e t
"moon" <moon@discussions.microsoft.com> wrote in message 
news:B82C63D2-E3B0-496C-A083-920DDA352F8C@microsoft.com...
> struct TEST
> {
> int a;
> int b;
> };
>
> TEST test;
>
> if (!::ReadFile(m_hDisk, (void*)&test, sizeof(test), &read, NULL)
>  return false;
>
> I would like to write my code above.
> but ReadFile is always fail with INVALID PARAMETER.
>
> but..
> char test[512];
> if (!::ReadFile(m_hDisk, (void*)&test, sizeof(test), &read, NULL)
>  return false;
>
> is always ok ..
>
> I don't know why this operation always fail..
>
> 


Relevant Pages