[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2003-11-17
2
Medium Priority
?
950 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 9765849
Ooops, sorry, that should read

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

650 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