Reads the value of a key from the currently loaded configuration file.

  • If the key exists and its value is not blank then its value is returned in the buffer.
  • If the key does not exist or its value is blank then nothing is put in the buffer and the byte count returned will be 0.

Parameters:

sectionName

The name of the section where the key exists or will be added.

keyName

The key identifier.

buffer:

The buffer that will contain the key value.

bufferLen

The size of the buffer (used to prevent an overrun).

Return Value:        

The number of bytes put in the buffer (including the termination character).

Prototype Signature:


int IniFileReadKey(const charsectionNameconst char *keyNamecharbufferint bufferLen);


An example of how this function could be used is shown below.

#include <malloc.h>
#include <string.h>
#include "api.h"

int main()
{
   success successful;
   int bufferLen = 1024;
   char* responseBuffer = malloc(bufferLen);
   int bytesCopied;

   //Initialize the library with a specific configuration file
   successful = Initialize("C:\\Temp\\MyConfig.ini");
   if(!successful)
   {
       //Get the key value
       bytesCopied = IniFileReadKey("Path_1", "SwitchPath", responseBuffer, bufferLen);
       if(bytesCopied > 0)
           printf("Path_1 has a switch path of %s" ,responseBuffer);
       else
           printf("No switch path is set");
   }
}