False FError return at INI file creation

Moderator: Rathinagiri

Post Reply
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

False FError return at INI file creation

Post 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
Screen2.png (34.97 KiB) Viewed 7575 times
Then I adjusted as follows:
Screen3.png
Screen3.png (39.34 KiB) Viewed 7573 times
This solved but is strange because error 2 (File not found) is returning but with File() it is existing file. :shock:
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: False FError return at INI file creation

Post by srvet_claudio »

Ok thanks Pablo
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

False FError return at INI file creation

Post 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
Screen14.png (66.74 KiB) Viewed 7447 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 ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: False FError return at INI file creation

Post 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.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

False FError return at INI file creation

Post 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
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: False FError return at INI file creation

Post by srvet_claudio »

Windows work with UTF16LE
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: False FError return at INI file creation

Post by Pablo César »

16 is compatible with old, 32 and 64... and same for FMG files when be UNICODE, of course.

Thank you.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

False FError return at INI file creation

Post 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. :oops:

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. :mrgreen:
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: False FError return at INI file creation

Post 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
Post Reply