1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Rep Power

    [Help] C program Read string .ini file or .cfg file

    Hello master :D
    i need help..
    i want to read .ini file or .cfg file in my .dll from C program.

    example contents of ini file :

    in my C program

    #include <windows.h>

    char INIValue[25];
    char myname= GetPrivateProfileString("Setting", "Name", "Default", INIValue, 25, ".\\file.ini");

    How to read myname(Nobita) from .ini file to my .dll file..

    thanks before, sorry my english bad :)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Rep Power
    The return value of GetPrivateProfileString is a DWORD NOT a character string. The return value is is the number of characters copied to INIValue not including the null terminating character. You'll have to pass INIValue to your DLL. Passing it to the DLL is done by simply passing INIValue as a parm in your defined DLL function. This is DLL 101 coding and should be very easy to do.

    The first parm in GetPrivateProfileString is the Section name. In this case it is Setting. The second parm is the KeyName which is Name. The third parm is a default return value which is returned if the Keyname cannot be found. In this example, the string "DefaultName" will be returned if the key does not exist. In other words, the variable ININvalue will contain "DefaultName" if the Name key does not exist. The fourth parm is the variable to hold the value returned by the function. The fift parm is the sizeof this variable. And finally, the sixth parm is the name of the ini file.

    #include <windows.h>
    #include <stdio.h>
    int main(void)
    char INIValue[25] = {0};
    	GetPrivateProfileString("Setting", "Name", "DefaultName", INIValue, sizeof INIValue,".\\file.ini");
    	printf("%s\n", INIValue);
    return 0;

IMN logo majestic logo threadwatch logo seochat tools logo