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