If you have unicode app and "unicode" file (in Windows parlance,
that's UTF-16 encoding), yes. UTF-8-encoded file didn't work last time
I tried.
Goran.
On Fri, 21 Aug 2009 01:13:22 -0700 (PDT), singurd <sin...@yahoo.com> wrote:
>Can i use GetPrivateProfileString/WritePrivateProfileString to read/
>write unicode strings from a file ?
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Trick: if the file does not exist, or exists but it is not Unicode, then
the functions will convert everything to ANSI.
If you want to be unicode, then create an empty file with a BOM only
(FE FF) and then everything you write will be Unicode.
http://blogs.msdn.com/michkap/archive/2006/09/15/754992.aspx
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
--
Serge.
http://www.apptranslator.com - Localization tool for your MFC applications
"Goran" <goran...@gmail.com> wrote in message
news:fd7257b6-8139-429d...@e27g2000yqm.googlegroups.com...
On Sat, 22 Aug 2009 01:04:10 -0700, "Mihai N." <nmihai_y...@yahoo.com> wrote:
>> Can i use GetPrivateProfileString/WritePrivateProfileString to read/
>> write unicode strings from a file ?
>
>Trick: if the file does not exist, or exists but it is not Unicode, then
>the functions will convert everything to ANSI.
>If you want to be unicode, then create an empty file with a BOM only
>(FE FF) and then everything you write will be Unicode.
>
>http://blogs.msdn.com/michkap/archive/2006/09/15/754992.aspx
That is not my blog, it belongs to Michael Kaplan (MS)
Note that I primarily am reporting errors of documentation. Sometimes I point out that
the design is flawed. But mostly, it is the omission of crtical information that should
have been written down.
The issue of "carrying settings around" sometimes suggests .INI files, so more people use
them than Microsoft intended. So the reality is that this behavior needs to be
documented, and the failure to provide clear documentation of this interesting behavior is
the "error" I want to cite.
joe
On Sat, 22 Aug 2009 14:49:47 -0700, "Mihai N." <nmihai_y...@yahoo.com> wrote:
>> Fascinating! Could I incorporate parts of that article into my MSDN Errors
>> document, with a hyperlink to your document?
>> joe
>
>That is not my blog, it belongs to Michael Kaplan (MS)
WritePrivateProfileString Function (Windows):
http://msdn.microsoft.com/en-us/library/ms725501.aspx
WritePrivateProfileSection Function (Windows):
http://msdn.microsoft.com/en-us/library/ms725500.aspx
I saved my text with Notepad as UTF-8 (so, with BOM), tried reading
back, and didn't get what I expected. I just re-tried, it's the same.
How did you do it?
Goran.
Must be UTF-16
Thanks to all
Its all in the file actualy, so i created the unicode file using the
code from the codeproject site.
_TCHAR bom = (_TCHAR)0xFEFF;
CFile* pFile = new CFile();
pFile->Open( strFile, CFile::modeCreate | CFile::modeWrite );
pFile->Write( &bom, sizeof(_TCHAR) );
pFile->Write( LPCTSTR(m_Text), m_Text.GetLength()*sizeof(_TCHAR) );
pFile->Close();
now the strFile file can contain unicode characters
Didn't Joe say you could just use the 'W' version of e.g.
WritePrivateProfileString --> WritePrivateProfileStringW, and it would
create a UTF-16 .ini file if it didn't already exist? That sounds much
easier.
-- David