| View previous topic :: View next topic |
| Author |
Message |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sat Aug 21, 2010 2:29 pm Post subject: Environment Variables and Win32 API Functions |
|
|
I'm trying to use FindFirstFile and FindNextFile using %appdata%\\* as my argument. Why won't it work?
| Code: | | LPCTSTR lpFileName = _T("%appdata%\\Macromedia\\Flash Player\\#SharedObjects\\*"); |
Produces exit code 3.
| Code: | | LPCTSTR lpFileName = _T("%appdata%*"); |
Produces exit code 2.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sat Aug 21, 2010 7:10 pm Post subject: |
|
|
Conversion disaster I'm trying to append the rest of the path onto the LPCTSTR for FindFirstFile but I'm having trouble.
Suggestions?
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sat Aug 21, 2010 7:20 pm Post subject: |
|
|
| ExpandEnvironmentStrings()
|
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Sun Aug 22, 2010 8:32 am Post subject: |
|
|
| justa_dude <3 buffer overflow
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Aug 22, 2010 10:50 am Post subject: |
|
|
| That function takes a size parameter..
|
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Aug 22, 2010 11:19 am Post subject: |
|
|
| Slugsnack wrote: | | That function takes a size parameter.. |
Don't worry about it. I did this and it worked.
| Quote: | LPTSTRING lpFileName = _tgetenv(_T("AppData"));
. . .
_tcscat(lpFileName, _T("\\Path\\To\\Folder\\*)); |
Thank you Wiccaan and Slugsnack.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Aug 22, 2010 4:42 pm Post subject: |
|
|
Be careful with things like that, you can lead into overflows and such.
| MSDN wrote: | | Returns a pointer to the environment table entry containing varname. It is not safe to modify the value of the environment variable using the returned pointer. |
You can define paths with MAX_PATH and just append to the buffers. Such as:
| Code: | TCHAR* lpEnvVar = _tgetenv( _T( "AppData" ) );
TCHAR tszFilePath[ MAX_PATH ] = { 0 };
_tcscpy_s( tszFilePath, MAX_PATH, lpEnvVar );
_tcscat_s( tszFilePath, MAX_PATH, _T( "\\Path\\To\\Folder\\*" ) ); |
Also with that, I'd suggest looking at the secured versions of the CRT library functions to prevent overflows and so on.
getenv_s:
http://msdn.microsoft.com/en-us/library/tb2sfw2z%28VS.80%29.aspx
_________________
- Retired. |
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Aug 22, 2010 9:28 pm Post subject: |
|
|
| Wiccaan wrote: | Be careful with things like that, you can lead into overflows and such.
| MSDN wrote: | | Returns a pointer to the environment table entry containing varname. It is not safe to modify the value of the environment variable using the returned pointer. |
You can define paths with MAX_PATH and just append to the buffers. Such as:
| Code: | TCHAR* lpEnvVar = _tgetenv( _T( "AppData" ) );
TCHAR tszFilePath[ MAX_PATH ] = { 0 };
_tcscpy_s( tszFilePath, MAX_PATH, lpEnvVar );
_tcscat_s( tszFilePath, MAX_PATH, _T( "\\Path\\To\\Folder\\*" ) ); |
Also with that, I'd suggest looking at the secured versions of the CRT library functions to prevent overflows and so on.
getenv_s:
http://msdn.microsoft.com/en-us/library/tb2sfw2z%28VS.80%29.aspx |
Thanks Wiccaan. Areas that I always fall short on are these access violations because I'm doing something I'm not suppose to and overflows.
|
|
| Back to top |
|
 |
|