Problems using FindFirstFile in NT

Started by
6 comments, last by etran1 22 years, 8 months ago
I need to read in the contents of a directory on an NTFS volume, but I always get an access violation in ntdll.dll. It''s trying to reference 0x00000000. Any ideas as to what might be causing this? Eric
Advertisement
It could be any number of issues, so seeing your code would be helpful.
It''s the first thing that gets called after my window creation section. The call is:

WIN32_FIND_DATA data;
FindFirstFile("C:\\*", data);

It crashes while attempting to complete this function.

I''m using VC++ 5.0 SP3
Hi!

I think you have to pass a pointer to the function...
I guess your code should look like:

WIN32_FIND_DATA data;
FindFirstFile("C:\\*", &data);

(recognize the "&")

CU
Dolphin

Sorry, it was supposed to be

WIN32_FIND_DATA * data;
FindFirstFile("C:\\*", data);
WIN32_FIND_DATA * data;
FindFirstFile("C:\\*", data);

Here''s the problem; data is a pointer to somewhere in memory at random. In a debug release it may be NULL, but the point is you need to pass in a pointer to some memory that FindFirstFile can fill out. So create a WIN32_FIND_DATA structure on the stack using :

WIN32_FIND_DATA data;

then tell the function where the data is on the stack using

FindFirstFile( "C:\\*", &data );
Your code would cause an error like that, like Anon said. But I''m assuming you would know to initialize the pointer before something like that, so I''m guessing you just didn''t include the pointer being initialized in the code in your post. If that''s the case, I have no idea what''s wrong. But, if you didn''t initialize the pointer, then definately fix that, or just don''t use a pointer at all and pass the structure itself by reference.
I hate coding when I''m tired. The mistakes I make...

Thanks, I''ll need to check at work but it should work fine now.

This topic is closed to new replies.

Advertisement