Hi
I try to flush the Cache of a .INI-File in .DLL in order to make sure all data is written on the disk before I hand over control to an other program, that will read this .INI-file. The .INI-File is handled by means of WritePrivateProfileString/GetPrivateProfileString.
However there seems to be a problem under certain circumstances: we do get an error 70. The occurence of the problem seems to be limited to 2 machines of one (1) customer (running WinXP). The DLL is installed on at least 25 other machines (none of them the same customer as above) too and there we have no reports of such a problem there. The calling application is unique to the customer having problems.
I added 2 MSGBOXes to my code in order to hunt he error:
The Messagebox shows up randomly and gives the following message:
InfileOps.Ini_Flush -- unexpected Result (2). ErrCode: 70
ErrCode: 70: Permission denied - (%ERR_PERMISSIONDENIED)
-- You tried to write to a write-protected disk. This error can also be generated as a result of network permission errors, such as accessing a locked file, or a locked record. It can also occur when attempting to open a subdirectory as a file.
Hmm, that explanation seems not fitting: the .INI generated by this DLL is on the local Drive C: and it uses always the same path and filename. Prior to writing to the file it is deleted and before I pass control to the calling application I rename the file. This seems to work, even aftert an Error 70. The .INI-file seems to be truncated in the application, meaning he first part of it seems to belong to the last call of the .DLL
I thought about removing the code to 'Check for a existence of file/write-protected disk/Permission denied first!' But I think I think this might just postpone the the problem to a situation a flush is tried without having written to a .INI...
Any good ideas what might cause this intermittent error on these machines?
I try to flush the Cache of a .INI-File in .DLL in order to make sure all data is written on the disk before I hand over control to an other program, that will read this .INI-file. The .INI-File is handled by means of WritePrivateProfileString/GetPrivateProfileString.
However there seems to be a problem under certain circumstances: we do get an error 70. The occurence of the problem seems to be limited to 2 machines of one (1) customer (running WinXP). The DLL is installed on at least 25 other machines (none of them the same customer as above) too and there we have no reports of such a problem there. The calling application is unique to the customer having problems.
I added 2 MSGBOXes to my code in order to hunt he error:
Code:
FUNCTION Ini_Flush(sFNPath AS STRING) AS LONG ' Flushs .INI-File Cache to Disk ' returns %FALSE for no errors, %TRUE for unable to write file LOCAL fhandle AS LONG LOCAL szFNPath AS ASCIIZ * 512 LOCAL funcRes AS LONG ' Check for a existence of file/write-protected disk/Permission denied first! Exit routine if found. szFNPath = sFNPath + CHR$(0) ON ERROR GOTO WriteIniError fhandle = FREEFILE IF DIR$(szFNPath) = "" THEN ' Avoid a file not found error on INPUT. OPEN szFNPath FOR OUTPUT AS fhandle CLOSE fhandle ELSE OPEN szFNPath FOR INPUT AS fhandle CLOSE fhandle END IF funcRes = WritePrivateProfileString(BYVAL %NULL, BYVAL %NULL, BYVAL %NULL, szFNPath) IF funcRes=0 THEN Ini_Flush = %FALSE ELSE ' Hmmm, I do not expect this ever to be executed. MSDN says: "... If the function ' fails, or if it flushes the cached version of the most recently accessed initialization ' file, the return value is zero. ..." MSGBOX "InifileOps.Ini_Flush -- unexpected Result (1)" Ini_Flush = %TRUE END IF GOTO WriteIniExit WriteIniError: fhandle = ERRCLEAR MSGBOX "InifileOps.Ini_Flush -- unexpected Result (2). ErrCode: " & STR$(fhandle) Ini_Flush = %TRUE WriteIniExit: ON ERROR GOTO 0 END FUNCTION
InfileOps.Ini_Flush -- unexpected Result (2). ErrCode: 70
ErrCode: 70: Permission denied - (%ERR_PERMISSIONDENIED)
-- You tried to write to a write-protected disk. This error can also be generated as a result of network permission errors, such as accessing a locked file, or a locked record. It can also occur when attempting to open a subdirectory as a file.
Hmm, that explanation seems not fitting: the .INI generated by this DLL is on the local Drive C: and it uses always the same path and filename. Prior to writing to the file it is deleted and before I pass control to the calling application I rename the file. This seems to work, even aftert an Error 70. The .INI-file seems to be truncated in the application, meaning he first part of it seems to belong to the last call of the .DLL
I thought about removing the code to 'Check for a existence of file/write-protected disk/Permission denied first!' But I think I think this might just postpone the the problem to a situation a flush is tried without having written to a .INI...
Any good ideas what might cause this intermittent error on these machines?
Comment