Solved

Making DLL Parameter optional

Posted on 2006-07-22
6
237 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 125 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

756 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