Solved

Making DLL Parameter optional

Posted on 2006-07-22
6
234 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
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.

 
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

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

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

861 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

23 Experts available now in Live!

Get 1:1 Help Now