BOOL setContent( LPSTR szContent )
{
HANDLE hFile;
BOOL bSuccess = FALSE;
DWORD dwTextLength;
hFile = CreateFile( "data.txt" , GENERIC_WRITE , 0 , NULL , CREATE_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL );
if( hFile != INVALID_HANDLE_VALUE )
{
DWORD dwWritten;
dwTextLength = strlen( szPassword );
if( WriteFile( hFile , szPassword , dwTextLength , &dwWritten , NULL ) )
bSuccess = TRUE;
else
LastErrorMessage( "setPassword()");
}
else
{
MessageBox(hwnd,"setPassword(): CreateFile failed.",0,0);
LastErrorMessage( "setPassword()"); // Format and Display GetLastError
}
return bSuccess;
}
CreateFile API here seems to always return INVALID_HANDLE_VALUE, and GetLastError reports that the operation completed successfully, but I still can't get a handle to the file.
What am I doing wrong?