Solved

.dll / Multiple outputs from a function

Posted on 2004-08-02
7
202 Views
Last Modified: 2010-04-24
I have a .dll with a source file that contains a function that accepts multiple inputs and provides only ONE output.  

Question: I would like to modify the function to provide MULTIPLE outputs from the .dll.  Please see my code below and suggest the code changes needed to allow for multiple outputs.  Thanks.

___________________________Source File Code

DllExport double _stdcall CALLBACK DOPM(double dataA, double dataB)
{ [blah, blah, blah]
    return outputData;
[I would like to return OutputDataB as well]
}


__________________________Header File Code

#define  MaxNum         5000
double dataA;
double dataB;
double outputData;

/*---------------------------------------------------------------------*/
#define DllExport  __declspec( dllexport )
/*---------------------------------------------------------------------*/
DllExport double _stdcall CALLBACK DOPM(double dataA, double dataB);
[I would like to return OutputDataB as well]

#endif
0
Comment
Question by:adorenbaum
  • 3
  • 2
7 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 11693108
You just can't return more than one value.
But you can return a value of type struct that has 2 doubles as members.

struct output
{
  double OutputData,OutputDatab;
}

Or you can use an extra parameter given by reference

DllExport double _stdcall CALLBACK DOPM(double dataA, double dataB, double &outputDataB)
{
[blah, blah, blah]
    outputDataB = mydataB;
    return outputData;

}
0
 

Author Comment

by:adorenbaum
ID: 11693606
Thanks for your reply.  Unfortunately, the DLL caller app does not support struct datatypes.  Also, the DLL caller app has some problems with pointers.  As a possible work around, I would like to take your suggestion of passing a pointer but I would like to pass the pointer to a second function within the same DLL.  The only purpose of this second DLL function would be to return a VALUE (not a pointer) to the DLL calling app.  In this manner, the DLL calling app would make two calls to two  different functions - one that returns the value of OutputData, the second returns the value of OutputDataB.  Can you suggest code for this?   Thanks.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11693701
I'm not sure I follow. But le me explain my second suggestion:

DllExport double _stdcall CALLBACK DOPM(double dataA, double dataB, double &outputDataB)
{
[blah, blah, blah]
    outputDataB = mydataB; //<-- here I set the outputDataB var to some value
    return outputData;
}

double data1, data2, out, outB;
....
out = DOPM(data1, data2, outB);
//<- here outB will be set to the value of 'mydataB' from the dll.

Regarding your second dll function: if you call it from within the dll (e.g. "I would like to pass the pointer to a second function within the same DLL") the returned value will be returned to the dll.
"In this manner, the DLL calling app would make two calls to two  different functions" - how would you like this? I see a contradiction with the above coment
0
 

Author Comment

by:adorenbaum
ID: 11696691
Thanks for your clarification.  I regret I was not clearer in my earlier e-mail.

I understand your suggestion in your most recent e-mail.  Unfortunately, however, I'm not calling the .dll from C/C++ code.  I need to call the .DLL from a proprietary language of a third party app (not important but in case you know it Easylanguage - for Tradestation).  My work around is somewhat convoluted:

__________In Easy Language Code_____________

OutputDataA= DOPMfcnA(data1, data2);
OutputDataB= DOPMfcnB(dumbVAR);

__________In the C DLL___________________

DllExport double _stdcall CALLBACK DOPMfcnA(double dataA, double dataB, double &outputDataB)
{
[blah, blah, blah]
    outputDataB = mydataB; //pass this to DOPMfcnB
    return outputDataA;
}

DllExport double _stdcall CALLBACK DOPMfcnB(int dumbVAR)

{
[Do nothing other than return value of &outputDataB.  Can I some how have DOPMfcnA define outputDataB as a global variable without having to pass it directly into DOPMfcnB through "DllExport double _stdcall CALLBACK DOPMfcnB(int dumbVAR, double &outputDataB)"]

    return [??];//I would like to return the value input VALUE for &outputDataB
}

I hope this clarifies.  Granted this is not efficient but I'm restrained by the limitations of the caller app.  Thanks.
0
 
LVL 16

Accepted Solution

by:
nonubik earned 500 total points
ID: 11701153
Ok, it does clarify.

You can declare outputDataB global and the 2 dll functions like:

double g_outputDataB;

DllExport double _stdcall CALLBACK DOPMfcnA(double dataA, double dataB)
{
[blah, blah, blah]
    g_outputDataB = mydataB; //pass this to DOPMfcnB
    return outputDataA;
}

DllExport double _stdcall CALLBACK DOPMfcnB()
{
  return g_outputDataB;
}

And now take care to call always DOPMfcnA before DOPMfcnB, otherwise g_outputDataB may not have the desired value.
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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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