Page 1 of 1
False FError return at INI file creation
Posted: Fri Sep 16, 2016 12:12 pm
by Pablo César
Hola Claudio,
I have tested simple INI creation at Win7 and Win10.
In C:\hmg.3.4.3\SOURCE\Ini\h_ini.prg after HMG_CreateFile_UTF16LE_BOM returning a false error status.

- Screen2.png (34.97 KiB) Viewed 7875 times
Then I adjusted as follows:

- Screen3.png (39.34 KiB) Viewed 7873 times
This solved but is strange because error 2 (
File not found) is returning but with File() it is existing file.

Re: False FError return at INI file creation
Posted: Fri Sep 16, 2016 2:37 pm
by srvet_claudio
Ok thanks Pablo
False FError return at INI file creation
Posted: Wed Nov 23, 2016 1:52 pm
by Pablo César
Hi Claudio,
I do not know if you going to mess in these functions of INI file creation/reading.
I remember I claimed a time ago for HMG_CreateFile_UTF16LE_BOM is creating with an empty line in the first line of the file and I saw this:

- Screen14.png (66.74 KiB) Viewed 7747 times
Also it mentions:
Why is it only UTF16-little Endian?
In Notepad included with Windows, we can choose 3 encoding formats in Unicode. These are "Unicode" (UTF16-little Endian), "Unicode big Endian" (UTF16-big Endian), and "UTF-8". We can use only UTF16-little endian of these formats as an INI file format. The other encodings do not work correctly (you examine it once). Probably, the reason is that Windows NT, XP or later uses the encoding internally. This is why Windows particularly names UTF16-little Endian "Unicode".
So, It could it affects reading INI files the Unicode format ?
Re: False FError return at INI file creation
Posted: Wed Nov 23, 2016 3:41 pm
by srvet_claudio
Pablo César wrote:Also it mentions:
Why is it only UTF16-little Endian?
In Notepad included with Windows, we can choose 3 encoding formats in Unicode. These are "Unicode" (UTF16-little Endian), "Unicode big Endian" (UTF16-big Endian), and "UTF-8". We can use only UTF16-little endian of these formats as an INI file format. The other encodings do not work correctly (you examine it once). Probably, the reason is that Windows NT, XP or later uses the encoding internally. This is why Windows particularly names UTF16-little Endian "Unicode".
So, It could it affects reading INI files the Unicode format ?
No.
False FError return at INI file creation
Posted: Thu Nov 24, 2016 11:04 am
by Pablo César
Claudio, could you confirm us what would be the ideal UNICODE standard for INI files?
[tr][td]
Bytes[/td][td] [/td][td]
Encoding Form[/td][/tr]
[tr][td]00 00 FE FF[/td][td] [/td][td]UTF-32, big-endian[/td][/tr]
[tr][td]FF FE 00 00[/td][td] [/td][td]UTF-32, little-endian[/td][/tr]
[tr][td]FE FF[/td][td] [/td][td]UTF-16, big-endian[/td][/tr]
[tr][td]FF FE[/td][td] [/td][td]UTF-16, little-endian[/td][/tr]
[tr][td]EF BB BF[/td][td] [/td][td]UTF-8[/td][/tr][/table]
Because I'm working on with this:
FWrite( hFile, Chr(0xEF)+Chr(0xBB)+Chr(0xBF) ) // UTF-8-BOM
Instead of:
HMG_CreateFile_UTF16LE_BOM ( cIniFile ) because this C function making an empty line in the first line of the INI files.
Also which UNICODE standard for FMG files ?
Waiting for you directive.
Thank you in advanced.
I am taking the opportunity to make this article available:
http://unicode.org/faq/utf_bom.html
Re: False FError return at INI file creation
Posted: Thu Nov 24, 2016 11:59 am
by srvet_claudio
Windows work with UTF16LE
Re: False FError return at INI file creation
Posted: Thu Nov 24, 2016 12:11 pm
by Pablo César
16 is compatible with old, 32 and 64... and same for FMG files when be UNICODE, of course.
Thank you.
False FError return at INI file creation
Posted: Thu Nov 24, 2016 12:38 pm
by Pablo César
Pablo César wrote:Instead of:
HMG_CreateFile_UTF16LE_BOM ( cIniFile ) because this C function making an empty line in the first line of the INI files.
Sorry, my deduction: totally wrong !
You already told me that you could not skip this line.
And now I know it's because of the WritePrivateProfileString / API function and its
0xFF and
0xFE for UTF16LE_BOM at first as head of INI file.
Let's keep HMG_CREATEFILE_UTF16LE_BOM.
Sorry I was a hardheaded.

Re: False FError return at INI file creation
Posted: Sat Dec 24, 2016 2:31 pm
by KDJ
If ini file does not exist it is created by HMG_CreateFile_UTF16LE_BOM function and FError() is not updated.
And it seems to me, hFile variable should be initialized by -1, not 0.
Code: Select all
*-------------------------------------------------------------
FUNCTION BeginIni(name, cIniFile )
*-------------------------------------------------------------
LOCAL hFile := 0
* Unused Parameter
name := Nil
*
if HB_UAT("\",cIniFile)==0
cIniFile := ".\"+cIniFile
endif
If ! File( cIniFile )
// by Dr. Claudio Soto, December 2014
IF HMG_IsCurrentCodePageUnicode() == .T.
HMG_CreateFile_UTF16LE_BOM ( cIniFile ) // The Windows native Unicode character set is in UTF-16LE
ELSE
hFile := FCreate( cIniFile )
ENDIF
Else
hFile := FOpen( cIniFile, FO_READ + FO_SHARED )
EndIf
If FError() != 0
MsgInfo( "Error opening a file INI. DOS ERROR: " + STR( FError(), 2, 0 ) )
Return ""
else
_HMG_SYSDATA [ 219 ] := cIniFile
EndIf
FClose( hFile )
Return Nil
Solution #1, add after file creation:
hFile := FOpen( cIniFile, FO_READ + FO_SHARED )
Code: Select all
*-------------------------------------------------------------
FUNCTION BeginIni(name, cIniFile )
*-------------------------------------------------------------
//LOCAL hFile := 0
//replaced
LOCAL hFile
* Unused Parameter
name := Nil
*
if HB_UAT("\",cIniFile)==0
cIniFile := ".\"+cIniFile
endif
If ! File( cIniFile )
// by Dr. Claudio Soto, December 2014
IF HMG_IsCurrentCodePageUnicode() == .T.
HMG_CreateFile_UTF16LE_BOM ( cIniFile ) // The Windows native Unicode character set is in UTF-16LE
//added
hFile := FOpen( cIniFile, FO_READ + FO_SHARED )
ELSE
hFile := FCreate( cIniFile )
ENDIF
Else
hFile := FOpen( cIniFile, FO_READ + FO_SHARED )
EndIf
If FError() != 0
MsgInfo( "Error opening a file INI. DOS ERROR: " + STR( FError(), 2, 0 ) )
Return ""
else
_HMG_SYSDATA [ 219 ] := cIniFile
EndIf
FClose( hFile )
Return Nil
Solution #2, create file by fCreate() and fWrite() instead of HMG_CreateFile_UTF16LE_BOM().
In this case, HMG_CreateFile_UTF16LE_BOM function is not needed in the code (c_ini.c).
Code: Select all
*-------------------------------------------------------------
FUNCTION BeginIni(name, cIniFile )
*-------------------------------------------------------------
//LOCAL hFile := 0
//replaced
LOCAL hFile
* Unused Parameter
name := Nil
*
if HB_UAT("\",cIniFile)==0
cIniFile := ".\"+cIniFile
endif
If ! File( cIniFile )
// by Dr. Claudio Soto, December 2014
IF HMG_IsCurrentCodePageUnicode() == .T.
//HMG_CreateFile_UTF16LE_BOM ( cIniFile ) // The Windows native Unicode character set is in UTF-16LE
//replaced
hFile := fCreate(cIniFile)
IF hFile > -1
fWrite(hFile, Chr(0xFF) + Chr(0xFE), 2)
ENDIF
ELSE
hFile := FCreate( cIniFile )
ENDIF
Else
hFile := FOpen( cIniFile, FO_READ + FO_SHARED )
EndIf
If FError() != 0
MsgInfo( "Error opening a file INI. DOS ERROR: " + STR( FError(), 2, 0 ) )
Return ""
else
_HMG_SYSDATA [ 219 ] := cIniFile
EndIf
FClose( hFile )
Return Nil
-----
Merry Christmas and Happy New Year 2017 from Poland!
Krzysztof aka KDJ