Solved

Making DLL Parameter optional

Posted on 2006-07-22
6
233 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

759 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

18 Experts available now in Live!

Get 1:1 Help Now