Solved

Making DLL Parameter optional

Posted on 2006-07-22
6
238 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
[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
  • 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
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!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

732 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