Page 1 of 1
Help with function win32 to wince functions
Posted:
Dec 6, 2001 @ 8:14pm
by R0B
Ok, here is the first of many questions that I will be asking on my epic quest to pot a program that will be revealed when it is nearly done (or at least capable of having a screen shot taken of it. If I port it completely, then at least the 720 owners, if not all ppc owners are in for a real treat.<br><br>Ok, Here are the first two functions I am haveing porblems finding in the hpc2000 sdk<br>1. access(const char *, int); //Located in IO.h<br>2. _findfirst(const char *, struct _finddata_t *); //Located in IO.h<br><br>The code where these two functions are used will follow, but here is what I already know about them. (1 refers to access, and 2 reffers to _findfirst)<br>1. Checks to see if you have some type of permission to access a file. In my case, checks for read permision.<br><br>//Code<br>miscvar=access(filename,4); //Checks to see if you can read the file <br><br>2. (Not sure about this one). Searches for all files that have "const char *", and stores results at "struct _finddata_t *" ???<br><br>//Code<br>if((miscvar=_findfirst("*.*",&miscvar2))!=-1) //Looks for all files???<br><br><br>If you could please help me emulate or get a good substitution for these files I would greately appriciate it. Thanks.
Re: Help with function win32 to wince functions
Posted:
Dec 6, 2001 @ 11:32pm
by Digby
Re: Help with function win32 to wince functions
Posted:
Dec 6, 2001 @ 11:43pm
by Dan East
Heh heh!
I guess you type faster than me Digby. There, now you have two solutions to a problem using two different mechanisms, from two great coders.
<br><br>Dan East
Re: Help with function win32 to wince functions
Posted:
Dec 6, 2001 @ 11:44pm
by Dan East
The Windows API FindFirstFile, FindNextFile and FindClose will provide the solution to implementing both those functions. FindFirstFile and FindNextFile fill a struct (WIN32_FIND_DATA) with information about the found file (attributes, file times, size, etc). Check WIN32_FIND_DATA::dwFileAttributes for the bits FILE_ATTRIBUTE_READONLY to be set set for the access function. Ahh, heck, I'll just code _access for you:<br>[fixed]<br>int _access(const char *path, int mode) {<br> //Have to convert to UNICODE<br> TCHAR fname[MAX_PATH];<br> MultiByteToWideChar( CP_ACP, 0, path, -1,<br> fname, sizeof( fname )/sizeof( TCHAR ) );<br> <br> WIN32_FIND_DATA ffd;<br> //Get info on target file<br> HANDLE h=FindFirstFile( fname, &ffd );<br><br> if ( h==INVALID_HANDLE_VALUE )<br> return -1; //Can't find file<br> FindClose( h );<br><br> if (ffd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)<br> return 0; //Always return success if target is directory and exists<br><br> switch ( mode ) {<br> case 00: //Check existance<br> return 0;<br> case 06: //Check Read & Write permission<br> case 02: //Check Write permission<br> return ffd.dwFileAttributes&FILE_ATTRIBUTE_READONLY?-1:0;<br> case 04: //Check Read permission<br> return 0; //Assume always have read permission<br> } <br> //Bad mode value supplied, return failure<br> return -1;<br>}[/fixed]<br><br>That assumes a file can always be read, thus it obviously is not taking into account file locking due to access by an application. I doubt the true implementation of _access does that anyways - it probably goes by file permissions only.<br><br>Dan East
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 1:25am
by RICoder
You fuckin' guys! GEEKS!<br><br>Ok, only because I didn't get here first...<br><br>:-D
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 5:04pm
by Matt Keys
ok, now use them both and tell us which code is better/faster:)
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 8:17pm
by R0B
Alright, thanks for your help. I'll try both of them out in a minute, and see which one works better. You guys are great, but don't think that this was the only question you'll have to answer because there will be plenty more
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 9:32pm
by R0B
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 10:06pm
by Dan East
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 10:43pm
by Digby
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 10:55pm
by Dan East
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 11:15pm
by R0B
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 11:20pm
by R0B
Re: Help with function win32 to wince functions
Posted:
Dec 7, 2001 @ 11:34pm
by Dan East