Solved

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

Posted on 2003-11-17
2
934 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

863 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

24 Experts available now in Live!

Get 1:1 Help Now