Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindFirstFile Question

Status
Not open for further replies.

Kalisto

Programmer
Joined
Feb 18, 2003
Messages
997
Location
GB
Is there anyway to use the FindFirstFile() function without having to fill in all the data members of the 2 structs it is passed first ?

i.e. if I don't default the LPWIN32_FIND_DATA structure to a set of default values I get an error. But, as far as I can see, the LPWIN32_FIND_DATA can be empty as the FindFirstFile() function fills this in.

Is there a better way for me to look at a subset of folders on a Drive and be able to view each file and folder in turn, or am I stuck using FindFirstFile() ?

(I know this can easily be done in DOS, and with a host of other tools, but I want to do this bit of my project in C++ as there are less files to worry about moving about)

Cheers,
K
 
>> fill in all the data members of the [red]2 structs[/red] it is passed

There is only one struct according to my documentation?
Since the WIN32_FIND_DATA struct is an [out] parameter i would just memset it to 0's
Code:
memset( &wfd, 0, sizeof(wfd));
or
Code:
ZeroMemory(&wfd, sizeof(wfd));

-pete
 
class MyWIN32_FIND_DATA: WIN32_FIND_DATA
{
public:
MyWIN32_FIND_DATA()
{
some standard initialization here
}
};

MyWIN32_FIND_DATA x;
FindFirstFile( ..., &x,....);
.....

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
It's Ok, It was one of those problems that was staring me in the face.

I had declared it as of type LPWIN32_FIND_DATA, not WIN32_FIND_DATA.

I sometimes I hate working when I am tired.

Thanks guys, Im gonna go hang my head in shame and promise not to come here and ask any more stupid questions for at least a week

K
 
LPWIN32_FIND_DATA is the same with ot WIN32_FIND_DATA*.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I know, but that was defined at the top of the Sub, and I was using it at the bottom, assuming it was the struct, not the pointer to it.
Ho Hum,

cheers anyway

K
 
this is not a problem. If there is a problem with conversion from WIN32_FIND_DATA* to LPWIN32_FIND_DATA you can use pointer conversion:
WIN32_FIND_DATA z;
WIN32_FIND_DATA* x = &z;
LPWIN32_FIND_DATA y = (LPWIN32_FIND_DATA)x;
or
LPWIN32_FIND_DATA y = (LPWIN32_FIND_DATA)&z;
The same thing:
class MyWIN32_FIND_DATA: WIN32_FIND_DATA
{
...
public:
MyWIN32_FIND_DATA()
{
some standard initialization here
}
...
};

MyWIN32_FIND_DATA x;
FindFirstFile( ..., (LPWIN32_FIND_DATA)&x,....);

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Thanks, the only problem was me. I didn't realise what I had done, and so I couldn't figure out why it wouldn't work

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top