LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Ini_WriteToFile Error -93

I am having difficulty writing a simple Ini File.  I've created the Ini file with g_MyIniFile = Ini_New(0); and the used the standard Ini_PutSring() and Ini_PutInt() functions.  I then try writing to a file using nStatus = Ini_WriteToFile (g_MyIniFile, "c:/myTempIni.ini"); and I get a result of -93 (input/output error).  This library is simple enough that I'm baffled as to what might be causing this.  Any insight from anyone would be greatly appreciated.
 
CraigL
0 Kudos
Message 1 of 8
(4,545 Views)
Maybe you should try to write to "c:\\myTempIni.ini" instead of "c:/myTempIni.ini".
Just a guess, I use the Windows functions. I don't know if the CVI functions 'convert' such paths like some MS applications and the error is elsewhere.

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 2 of 8
(4,530 Views)

Hello CraigL,

In addition to CVI-User's comments, you can take a look at the INI shipping example to see how the file name is formatted and fed into the Ini_WriteToFile function.  The INI shipping example is located in <cvi folder>\samples\toolbox\ini.prj.

Thanks.

Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 3 of 8
(4,519 Views)

Some times you feel like a dunce...some times you don't.  It was indeed the formatting.  It requires c:\ instead of c:/ or c:\\.  Arghhh.  Thanks for the suggestions.

Craig

0 Kudos
Message 4 of 8
(4,488 Views)
I am also having difficulty writing to an INI file but in this case the entire file get erased as soon as the file is opened to write.  The program can read values from the file without problems but as soon as the file is opened to write everthing gets erased.


    GetProjectDir (dirName);
    MakePathname (dirName, "CableOffsets.ini", pathName);

    CableOffsetFile = Ini_New (0); 

    if (readWrite == 0)
    {
        Ini_ReadFromFile (CableOffsetFile, pathName);
      
        Ini_GetDouble (CableOffsetFile, section, "Tx", &TxLoss);
        Ini_GetDouble (CableOffsetFile, section, "Rx", &RxLoss);
      
        SetCtrlVal(CalMain, MAIN_TX_LOSS, TxLoss);
        SetCtrlVal(CalMain, MAIN_RX_LOSS, RxLoss);
    }
    else
    {
        Ini_WriteToFile (CableOffsetFile, pathName);
      
        GetCtrlVal(CalMain, MAIN_TX_LOSS, &TxLoss);
        GetCtrlVal(CalMain, MAIN_RX_LOSS, &RxLoss);
      
        Ini_PutDouble (CableOffsetFile, section, "Tx", TxLoss);
        Ini_PutDouble (CableOffsetFile, section, "Rx", RxLoss);
    }
    Ini_Dispose (CableOffsetFile); 


John Bessire


   
0 Kudos
Message 5 of 8
(4,478 Views)
Hello John.

According to the help for the Ini_WriteToFile() function, it "...writes the tag/value pairs in the list identified by Handle to the file identified by Pathname." Note also that "...if a file with that pathname already exists, it will be overwritten", i.e. truncated. This means that you must build the entire list in memory before writing it to the file.

The problem is that when you call Ini_WriteToFile(), immediately after Ini_New(), the list "CableOffsetFile" is empty.

Your code needs to be something like this:
    ...
    else
    {
        GetCtrlVal(CalMain, MAIN_TX_LOSS, &TxLoss);
        GetCtrlVal(CalMain, MAIN_RX_LOSS, &RxLoss);
      
        Ini_PutDouble (CableOffsetFile, section, "Tx", TxLoss);
        Ini_PutDouble (CableOffsetFile, section, "Rx", RxLoss);

        Ini_WriteToFile (CableOffsetFile, pathName);
    }
    Ini_Dispose (CableOffsetFile);

Regards,
Colin.

0 Kudos
Message 6 of 8
(4,470 Views)

I tend to stick to the SDK functions for reading or writing .ini files. GetPrivateProfileInt(), GetPrivateProfileString() and WritePrivateProfileString(), for example. Depending on the application, they might be easier to use.

JR

0 Kudos
Message 7 of 8
(4,463 Views)
I just tried revising the program like cdk52 suggested to put the Write command after the Ini_Put commands but it still erases the file.

Ini_PutDouble (CableOffsetFile, section, "Tx", TxLoss);
Ini_PutDouble (CableOffsetFile, section, "Rx", RxLoss);

Ini_WriteToFile (CableOffsetFile, pathName);

There is another program that someone else wrote that will lose all the data after an Ini_Put command.  This occurs about once a month but the rest of the time it writes correctly.

I am going to switch over to the Windows API functions since I have used then before and know they work.
0 Kudos
Message 8 of 8
(4,450 Views)