Solved

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

Posted on 2003-11-17
2
929 Views
Last Modified: 2012-06-27
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)



0
Comment
Question by:weslondon
  • 2
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9765840
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 "
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 9765849
Ooops, sorry, that should read

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now