Archived

This topic is now archived and is closed to further replies.

etran1

Problems using FindFirstFile in NT

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 );

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites