Link to home
Start Free TrialLog in
Avatar of weslondon
weslondon

asked on

Borland C++ .... SetupGetStringField (returning a value from a INF File)

Hello,

I've used an INF file on our current application to store some parameters.
However, we appear to be experiencing problems with the SetupGetStringField function.
i.e. it doesn't appear to be returning anything.


I've used SetupOpenInfFile to open the INF file and SetupFindFirstLine to find the first line which contains the relevant section and key.
However SetupGetStringField  doesn't appear to be working.


Can you have a look at the code to see what the problem is and/or suggest a different approach which be easier?

hope you can help.


Cheers, weslondon


~~~~~~~~~~~~~

        DWORD dwResult;
        HINF hInf;                     //variable to hold the INF handle
        UINT ErrorLine;                //variable to hold errors returned

        INFCONTEXT aContext = {0};
        char *  aReturnBuffer;
        DWORD aReturnBufferSize;
        PDWORD aRequiredSize;

        BOOL aLineFound = 0;
        BOOL aStrEntryFound = 0;

        strcpy (aInfName, "C:/Inf.inf");

        hInf = SetupOpenInfFile (
               aInfName,
               NULL,
               INF_STYLE_WIN4,
               &ErrorLine);           //line number of the syntax error

        if (hInf == INVALID_HANDLE_VALUE)
        {
            return NULL;
        }
        else
        {
            // Find correct line - using aSection and aKey

            aLineFound = SetupFindFirstLine(
                hInf,              // handle to an INF file
                aSection,      // section in which to find a line
                aKey,              // optional, key to search for
                &aContext      // context of the found line
            );

            if (aLineFound)
            {
                // Extract value using &aContext

                aStrEntryFound = SetupGetStringField(
                &aContext,                    // context of the INF file
                1,                            // index of the field to get
                aReturnBuffer,            // optional, receives the field
                aReturnBufferSize,            // size of the provided buffer
                NULL                      // optional, buffer size needed
                );
            }
            if (aStrEntryFound)
            {
                SetupCloseInfFile(hInf);
                return aReturnBuffer;
            }

~~~~~~~~~~~

N.B aStrEntryFound is false
(i.e. nothing returned in aReturnBuffer)



Avatar of jkr
jkr
Flag of Germany image

You are not specifying a valid return buffer - use

       char *  aReturnBuffer [ 1024]; // or whatever size is appropriate
       DWORD aReturnBufferSize = sizeof ( aReturnBuffer);

The docs state: "ReturnBuffer
This optional parameter points to a caller-supplied buffer "
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial