.dll / Multiple outputs from a function

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
adorenbaumAsked:
Who is Participating?
 
nonubikConnect With a Mentor Commented:
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
 
nonubikCommented:
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
 
adorenbaumAuthor Commented:
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
 
nonubikCommented:
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
 
adorenbaumAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.