Showing results for 
Search instead for 
Did you mean: 

trouble with writing to registry from ini

I can't seem to get Ini_WriteToRegistry to work. I ini file into memory with Ini_ReadFromFile, but then I tried to write it to the registy I got -52 as an error code. Anyone have any ideas? has any one used Ini_WriteToRegisty?
0 Kudos
Message 1 of 4
-52 is not a typical error from this function, so I couldn't really guess. We provide the source code for you for the inifile tool (inifile.c). I would add the source code to your project and step through it to see where the error is occurring and what the values of the variables look like for the SDK function returning the error. Maybe that will help the error make sense.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 4

I too have had trouble and this appears to be the reason:

If you are using IniFile.c, the problem may be that your SubKey does not exist yet.  This causes Ini_ClearRegistry( ) to post an error and Ini_WriteToRegistry( ) doesn't get a chance to call RegCreateKeyEx( ) which is needed in order create your SubKey.  (The error returned is -5002, ToolErr_ErrorReadingFile)   The workaround is to call RegCreateKeyEx( ) directly to create your SubKey before calling Ini_WriteToRegistry( ). If you're intent on using IniFile.c, then you can hack line at 1452 or (or thereabouts) so that the return from Ini_ClearRegistry( ) doesn't take the error route if the SubKey doesn't exist. 

Message Edited by WhiteSalmon on 08-10-2006 11:03 AM

Robin Knoke
CVI Developer since 1994
Message 3 of 4

After modifying IniFile.c as suggested by WhiteSalmon and including this file in the project, I solved the problem of writing subkeys to the registry that did not previously exist.


In LabWindows/CVI 8.1 the source file is found at "c:\Program Files\National Instruments\CVI81\toolslib\toolbox\inifile.c". The original line at 1452 was replaced so that Ini_WriteToRegistry() continues processing when error -5002 is encountered.



errChk (Ini_ClearRegistry(hrootKey, baseKeyName));



// Ini_WriteToRegistry() returned -5002 when subkeys did not exist.

error = Ini_ClearRegistry(hrootKey, baseKeyName);
if (error != -5002)


0 Kudos
Message 4 of 4