using ReadFile()

Started by
0 comments, last by Joker2002 20 years, 7 months ago
Having trouble using ReadFile. Pretty sure it has to do with my pointer variable. Any help appreciated.


int main(void)
{
char filename[] = "text.txt";
long *pointer = NULL;
HANDLE file_handle;

     if ((file_handle = CreateFile(filename,
                              GENERIC_READ,
                              FILE_SHARE_READ,
                              NULL,
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL)) == INVALID_HANDLE_VALUE)
   return(0);

    ReadFile(file_handle, pointer, 1, 0, NULL);
}
 
Assume text.txt has just one 8-bit character in the file. At the end of the code, pointer is always still NULL. By the way, I''ve tried just about every imaginable combination for the pointer variable type and no luck.
Advertisement
Well, the pointer is pointing to NULL. That''s why.

long *pointer = GlobalAlloc (0, sizeof (long));ReadFile (...,pointer,...); 

Now you''re talkin''!

This topic is closed to new replies.

Advertisement