Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WritePrivateProfileString (INI file not updated after power off)

0 views
Skip to first unread message

Ung

unread,
Dec 8, 1998, 3:00:00 AM12/8/98
to
Hi All

I was writing a simple tracking support program to write statistic data
into INI file (WritePrivateProfileString) after processed each record.
However, when the system crash (for eg, reset the computer) the INI file
seem to be not updated. I have tried to display a message after each
WRITE and then take a look on the INI, and it’s work fine.

I have tried to flush the cache by setting first 3 parameters to NULL,
but it doesn’t work.

Thanks for any help!

Best Greeting
Ung

Andrew Kotsar'

unread,
Dec 8, 1998, 3:00:00 AM12/8/98
to
Hi, Ung!
If your program write the log and computer crash is possible, maybe using of
WritePrivateProfileString is bad solution. This function read all ini file
in memory buffer, modify it and write back to disk. If crash is occurred ini
file may be broken.
I suppose, nothing can be made.
The best decision is writing in text file without WinAPI ini subroutines.
First, you must open it, set his length enough to write all your log
information, close it and open again for writing. After these operations,
even if failure is occurred, information in your log file will be safe.

Sorry for my English.

--
Andrew Kotsar'
IT specialist
Moscow
Sodexho AO Russia

Ung wrote in message <366CDC7C...@tm.net.my>...

Murray Thayer

unread,
Dec 8, 1998, 3:00:00 AM12/8/98
to
Hi

This code flushes ok for me.


Private Declare Function WritePrivateProfileStringFlush Lib "kernel32"
Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As Long, _
ByVal lpKeyName As Long, _
ByVal lpString As Long, _
ByVal lpFilename As String) As Long

Public Function SetIniFlush(HoldFile as string) As Boolean
WritePrivateProfileStringFlush 0, 0, 0, HoldFile
SetIniFlush = True
End Function

Ung

unread,
Dec 9, 1998, 3:00:00 AM12/9/98
to Murray Thayer
Hi

I was using the WritePrivateProfileString in conjunction with the
DoEvents.
Here are the code...

Sub Record_Process()
Initialize and Write to INI file
While EndOfProcess
DoEvents
Wend
Terminate Process
End sub

At the same time, there is a timer which will fire an event to call
Step_Process to step through each record. So, upon completion of
processing each record, the INI file should be updated and write to disk
file instead of cache.

Sub Timer1_Timer()
Call Step_Process()
End sub

Sub SetIniFlush()
If WritePrivateProfileString( 0&, 0&, 0&, IniFile) then :
End sub

Sub Step_Process()
...
if WritePrivateProfileString(sections, entry,key,IniFile) then:
SetIniFlush()
End sub

I called the SetIniFlush inside the Step_Process but it seem to be working
only for the first record.For the subsequent processed record, the INI
file is not updated.

Thanks for help!

Regards
Ung

Andrew Kotsar'

unread,
Dec 9, 1998, 3:00:00 AM12/9/98
to
Hi, Ung!
WritePrivateProfileString(0&, 0&, 0&, IniFile) is well-known and you code
work at me! But it is insecure. Each flush of ini write entire ini-buffer to
disk - information will be lose if failure raise.
If you want - send me all your module, maybe we'll find error in code
together?
0 new messages