Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Making DLL Parameter optional

Posted on 2006-07-22
6
Medium Priority
?
242 Views
Last Modified: 2010-04-02
I creating a "Wrapper DLL" in C++ that wraps around a Third Party API. I will then use VB to interface with the Wrapper so I can communicate with the API..

I have a function called "readGeneralAccountInfo".  There is a corresponding function within the API that will allow me to pull back a large amount of info from a number of methods.

To keep my coding Simple in VB and easy to maintain in C++, I don't want to create a c++ method for every piece of information that can be pulled from the API readGeneralAccountInfo but rather make it a parameter that is passed into the Wrapper.

How do I make that parameter optional in c++ so when I call that method from VB, I don't have to pass in the parameter for a variable that I may not necessarily want to pull at that time...

Example:

Frm the ReadGeneralAccountInfo method, I can read account balance, account status, Account type.  I want them all available in one method rather than 3 seperate methods, but if I have a list of accounts that I just need to pull the balance on, I don't want to have to declare and pass in vairables for all 3.
0
Comment
Question by:jpmc_cmsops
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:mrwad99
ID: 17160195
Does the default method of giving the parameter a value in the declaration, eg

Func( int i = 10 );

not work ?

0
 

Author Comment

by:jpmc_cmsops
ID: 17163634
I will be calling the function from VB and most (so far) are string variables that the only way I can get the function call to work is to pass in an already declared variable....

dim myString as string * 255


0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 250 total points
ID: 17168594
You need to make a generalized fetch method that could get data by name and return them as strings (you might return VARIANT type, but believe it's easier to return a string beside you would need numeric values only).

In C++  (unfortuantely I don't know much of VB)
#include <string>
#include <sstream>
using namespace std;

bool getData(const char* key, char* data, int bufsize)
{
     string skey = key;
     if (skey == "balance")
     {
           // get balance data
           double d = getbalance();
           ostringstream oss;
           oss >> d;
           string sdata = oss.str();
           if (sdata.length() >= bufsize)
                return false;  // buffer not big enough
           strcpy(data, sdata.c_str());
     }
     else if (skey == "account type")
     {
           ..
     }
     else if (skey == "account status")
     {
           ...
     }
     else
          return false;   // invalid key
 
    return true;
}

Note, instead of a string key, you could use a numeric identifier (define it as an enum in C++). Then, the if / else if  cascade might be replaced by a switch statement.



Regards, Alex
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 17173442
Why do you give a C grade for a 125 points question?

The answer is at least a B and if you would have given feedback we could have made it an A.
0
 

Author Comment

by:jpmc_cmsops
ID: 17175790
I apoligize, I didn't realize that the "Grade" made a difference.  I thought this was a point driven.  

I'm new to this site so please accept the apology.   If I could change it, then I would give a B grade for it...

Again....Sorry.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 17188500
>>>> I didn't realize that the "Grade" made a difference.

yes, grade is more important than points. First, it honours the time and efforts of experts participated on thread regardless whether their answer was accepted or not. Second, the grade is multiplicator for the expert points accounted. Grade C only gives double expert points while grade A giives times four ...

grade C actually is the baddest grade you can give. It is appropriate if you don't get answers though you asked for. Instead of accepting an answer giving a C grade, you should ask for a 'Delete and Refund' that definitively would be granted if the request is reasonable.

Here I gave a valid answer/solution to your question. If for some reason you can't apply it, you should have given feedback prior to accepting the answer giving a C grade.

>>>> If I could change it, then I would give a B grade for it...

You can make a request to EE Support. They will change the grade or reopen the thread so that you can change it yourself.

BTW, if you would reopen the question and tell what made you disgrade the solution I posted, we most likely find a better solution.

Regards, Alex
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

810 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