Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have following code:

C++
hFile = CreateFile(stTmp, GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
    DWORD err = GetLastError();
    return 0;
}


Here stTmp is "%allusersprofile%\853.log" in Createfile

it is giveing error code 3 (File path not found)

Can any one help why I am getting this error?
Posted
Updated 18-Dec-12 3:06am
v2

Call ExpandEnvironmentStrings[^] to expand '%allusersprofile%' to whatever it's set to in the environment.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Dec-12 20:55pm    
A 5,
-SA
Espen Harlinn 30-Dec-12 5:25am    
Thank you, Sergey :-D
The '%allusersprofile%' environment variable is not resolved by the CreateFile[^] function.

Use the getenv[^] function to retrieve the environment variable and add the file name to it before using it in the CreateFile function.
 
Share this answer
 
Comments
Espen Harlinn 18-Dec-12 9:04am    
Beat you to it, but it is correct so you've been 5'ed :-D
André Kraak 18-Dec-12 9:13am    
Thanks, gave one (or five actually) back. :)
Espen Harlinn 18-Dec-12 9:14am    
Thank you, André :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900