please help me recognize this piece of code!

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 15
Reputation: Mahsa_C++ is an unknown quantity at this point 
Solved Threads: 0
Mahsa_C++ Mahsa_C++ is offline Offline
Newbie Poster

please help me recognize this piece of code!

 
0
  #1
Jan 25th, 2009
Hello everyone,
I'm into writting a project ,that's all about dealing with directories and more specificly to code something that finally well work as"windows command prompt" in standard console....
i Got alot help from the experts here & got alot progressed, But a bug has occured in between:
yestreday i got announced that we've got to use the WIN32_FIND_DATA stuct and use it's members to deal with directories only. To be given more help the teacher wrote down this code for us :
  1. bool isdirecory(wchar_t *temp)
  2. {
  3. WIN32_FIND_DATA filedata;
  4. HANDLE h.search;
  5. h.search=FindFirstFile(temp, & filedata);
  6. if (filedata.dwattributes==16)
  7. return true;
  8. else
  9. return false;
  10. }
this function supossedly is to identify whether the variable "temp" is a directory in the system or not !
But the fact is that i cant realize what process is going on. all my searches about this stuct looks quite wierd i cant make head or tails of. ccan any one pppplllleeeaassse clarify for me what do the items above, each one of them, do ? .....as well as letting me know how i can pass an argument to this function ?, is the argument "wchar_t" the address we're gonna check its validity ...or what is it at all ? arent all addresses in char* mode ?... how to modify them if yes ??? ....i feel totally mixed up with these few lines ! any helps will highly be appriciated !
Thanx in advance
Mahsa M
19
student of computer engeneering **in the very begining of course**
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: please help me recognize this piece of code!

 
0
  #2
Jan 25th, 2009
The only weird thing is h.search isn't a valid variable name.

As for the rest, have you read these?
http://msdn.microsoft.com/en-us/library/aa365740.aspx
Do you see where 16 comes from?

http://msdn.microsoft.com/en-us/libr...18(VS.85).aspx
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 15
Reputation: Mahsa_C++ is an unknown quantity at this point 
Solved Threads: 0
Mahsa_C++ Mahsa_C++ is offline Offline
Newbie Poster

Re: please help me recognize this piece of code!

 
0
  #3
Jan 25th, 2009
Thank u very much,
yeah, i alreday had taken a look at those MSDN pages, i know that 16 means the given address is a true directory.
but what still remains unsolved is that i don know how to pass an argument to this function.
for example if i'm supposed to detemin if "C:\program files\Firefox" is one of the existing directories of my computer, how can i use this function? .. i cant change it into wchar_t* !..my searches reveal confusing results !
would u write me a comprehensive example , with datas given, so that i betterly undersatnd? thank u very much.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: please help me recognize this piece of code!

 
0
  #4
Jan 25th, 2009
Well in windows, wchar_t should be TCHAR (scroll down to the examples in the links)

So perhaps
isdirecory( TEXT("C:\\program files\\Firefox") );
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: please help me recognize this piece of code!

 
0
  #5
Jan 25th, 2009
u can use
  1.  
  2. FindFirstFileW(...,...);
  3.  
  4. and dont forget
  5. WIN32_FIND_DATAW
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 15
Reputation: Mahsa_C++ is an unknown quantity at this point 
Solved Threads: 0
Mahsa_C++ Mahsa_C++ is offline Offline
Newbie Poster

Re: please help me recognize this piece of code!

 
0
  #6
Jan 25th, 2009
Thank u big time !
it now seems like i can be hopeful to get a nerve relief about performing my project.
So, Does the Function TEXT(qoate ) change a char* to wchar_t ??
it seems like it does so, but it does it abit more complicated than i thought at first...what does the term "qoate" exactly mean here ??
..when i use the code below:
[code]
char* str="C:\WINDOWS";
wchar_t* longstr=TEXT(str);
[\code]

im given the following error:
error C2065: 'Lstr' : undeclared identifier

so...how can i change it in a way that i be able to pass a string to the TEXT argument ?
..i need it since the user is to enter the directory address, and i am to determin wether he's entered wrong or write ?
Tanx alot
Mahsa
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: please help me recognize this piece of code!

 
0
  #7
Jan 25th, 2009
TEXT isn't a function, it's a macro.
So it's limited to "strings"

It's not a good idea to try to keep both forms in your program, except for when you absolutely have to choose one specific form for a particular case. Even then, try to minimise the scope so it doesn't pollute the rest of your code.

For example, you might do
TCHAR *str = TEXT("C:\\Windows");
TCHAR *s2 = str;


Where you might have previously used strcpy to copy a string, you would use _tcscpy() instead, which does the right thing depending on whether you compile for ANSI or UNICODE.

This is a handy list-on-a-page of all the mapped API calls.
http://www.i18nguy.com/unicode/c-unicode.html



However, this being C++ (I assume, since this is the forum you posted on), you should start to look at the wide character equivalent of std::string to do most of the work for you.
Lets see how long it takes your teacher to enter the real world of C++.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 15
Reputation: Mahsa_C++ is an unknown quantity at this point 
Solved Threads: 0
Mahsa_C++ Mahsa_C++ is offline Offline
Newbie Poster

Re: please help me recognize this piece of code!

 
0
  #8
Jan 26th, 2009
Thank u Salem alot !!
yes, you're right, that would be bothering to try to use the both forms of wchar_t* and char*, so instead i'll try to deal with merely unicode charactors.
The link you put for me is surprisingly filtered .. i'll then try connections through different ways to see whether i can open it or not ?.. would u do me a favor and copy them for me on the page here ?...i'll highly appriciate it.

one more critical question:
Does WIN32_find_data structure provide me with something that i need to use to get a list of files & folders in a directory ? like what <Dir> does in windows... i viwed the data memebres of the struct, i couldnt find one...
If this struct is of no help, what recomandations do u have ??

ps-Yeah, u're right...Perhaps there's still long way till we learn wholy about c++, but the point was that i didnt know to which world ( c or c++) my question exactly refers! ( even worse!) i'm almost lost between my scattered knowledge of both worlds !
Thank uuuuu greatly.
Mahsa
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: please help me recognize this piece of code!

 
0
  #9
Jan 26th, 2009
The same info is on MSDN, just with more clicking.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 512 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC