False FError return at INI file creation
Moderator: Rathinagiri
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
False FError return at INI file creation
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.
Then I adjusted as follows:
This solved but is strange because error 2 (File not found) is returning but with File() it is existing file.
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.
Then I adjusted as follows:
This solved but is strange because error 2 (File not found) is returning but with File() it is existing file.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: False FError return at INI file creation
Ok thanks Pablo
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
False FError return at INI file creation
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:
Also it mentions:
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:
Also it mentions:
So, It could it affects reading INI files the Unicode format ?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".
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: False FError return at INI file creation
No.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 ?
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
False FError return at INI file creation
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
[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
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: False FError return at INI file creation
Windows work with UTF16LE
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Re: False FError return at INI file creation
16 is compatible with old, 32 and 64... and same for FMG files when be UNICODE, of course.
Thank you.
Thank you.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
False FError return at INI file creation
Sorry, my deduction: totally wrong !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.
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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Re: False FError return at INI file creation
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.
Solution #1, add after file creation:
hFile := FOpen( cIniFile, FO_READ + FO_SHARED )
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).
-----
Merry Christmas and Happy New Year 2017 from Poland!
Krzysztof aka KDJ
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
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
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