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

WritePrivateProfileString not closing file immediately

537 views
Skip to first unread message

Mike Olivieri

unread,
Aug 9, 1996, 3:00:00 AM8/9/96
to

I'm having trouble with a program and the only thing I can think of
sounds pretty strange to me. It seems that WritePrivateProfileString
doesn't finish its writing until sometime after the function has
supposedly completed (as in, I step over it debugging but I got some
strange behavior.)

The strange behavior is this:

I write to a file using WritePrivateProfileString and then try to print
that file out. Instead of the file being printed out nicely, the last
entries created by WPPPS are just some binary-type blocks. Though
really, when I open up the file as soon as I can after the
modifications, it is fine. I tried pausing (by waiting before stepping
into the printer loop) and that worked - the file printed out as
possible. Can anybody help? Here is some code...

WritePrivateProfileString("Companies", "number", (const char *)&num,
lpExistingFileName);
//snip
//(database closing and catch statements)
//snip
TRACE("Opening file for reading.\n");
CFile *fFile = new CFile(lpExistingFileName, CFile::modeRead);
CArchive *arFile = new CArchive(fFile, CArchive::load);
TRACE("Opening printer for writing.\n");
CFile *fPrinter = new CFile("c:\\temp\\1.txt", CFile::modeWrite |
CFile::modeCreate);
char byte;
UINT readsize;
TRACE("Reading in file and writing to printer buffer. \n");
do
{
readsize = arFile->Read((void *)&byte, 1);
fPrinter->Write((void *)&byte, 1);
}
while (readsize > 0);
TRACE("Flushing printer buffer and closing printer and file.\n");
arFile->Close();
fFile->Close();
fPrinter->Flush();
fPrinter->Close();

Thanks in advance,
mike

Gert Rijs

unread,
Aug 10, 1996, 3:00:00 AM8/10/96
to pce...@connix.com

Mike Olivieri wrote:
>
> I'm having trouble with a program and the only thing I can think of
> sounds pretty strange to me. It seems that WritePrivateProfileString
> doesn't finish its writing until sometime after the function has
> supposedly completed (as in, I step over it debugging but I got some
> strange behavior.)
>
> The strange behavior is this:
>
> I write to a file using WritePrivateProfileString and then try to print
> that file out. Instead of the file being printed out nicely, the last
> entries created by WPPPS are just some binary-type blocks. Though
> really, when I open up the file as soon as I can after the
> modifications, it is fine. I tried pausing (by waiting before stepping
> into the printer loop) and that worked - the file printed out as
> possible. Can anybody help? Here is some code...
>
<code snipped>
>
> Thanks in advance,
> mike

The 'privateprofile' functions cache the most recent ini-file in memory.
To force write to disk just access another Private ini file. I believe
that you can also call wpps with a NULL ini-filename to flush the last
ini-file to disk (not sure).

--
Gert Rijs
g...@wirehub.net (at home)
gert...@corp.ah.nl (at work)

Mike Olivieri

unread,
Aug 10, 1996, 3:00:00 AM8/10/96
to g...@wirehub.net, gert...@corp.ah.nl


Thanks! That fixed the problem. I simply put the following before
attempting to print, and it worked.

WritePrivateProfileString("","","","");

Thanks again!

David Connet

unread,
Aug 26, 1996, 3:00:00 AM8/26/96
to

In article <320C1C...@wirehub.net>, Gert Rijs <g...@wirehub.net> wrote:
>Mike Olivieri wrote:
>>
>> I'm having trouble with a program and the only thing I can think of
>> sounds pretty strange to me. It seems that WritePrivateProfileString
>> doesn't finish its writing until sometime after the function has
>> supposedly completed (as in, I step over it debugging but I got some
>> strange behavior.)
>>
>> The strange behavior is this:
>>
>> I write to a file using WritePrivateProfileString and then try to print
>> that file out. Instead of the file being printed out nicely, the last
>> entries created by WPPPS are just some binary-type blocks. Though
>> really, when I open up the file as soon as I can after the
>> modifications, it is fine. I tried pausing (by waiting before stepping
>> into the printer loop) and that worked - the file printed out as
>> possible. Can anybody help? Here is some code...
>>
><code snipped>
>>
>> Thanks in advance,
>> mike
>
>The 'privateprofile' functions cache the most recent ini-file in memory.
>To force write to disk just access another Private ini file. I believe
>that you can also call wpps with a NULL ini-filename to flush the last
>ini-file to disk (not sure).
>

Actually, it's a NULL everything except the filename. It's documented in the
help.

--------------------
Dave Connet
Dave_...@krinfo.com

My opinions are my own. I think...

0 new messages