hp746
asked on
how can i return multiple values from vc++ dll
i have written a dll in vc++ 6.
i have two variables to return one is _bstr_t and another one is short
how do i retun these variables
i have two variables to return one is _bstr_t and another one is short
how do i retun these variables
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If your two variables are global, and your just trying to access them from your executable (or another library) then you need to export them.
// .h Header of Library
extern MY_API int globalA;
extern MY_API int globalB;
// .cpp Source of Library
int globalA = 1;
int globalB = 2;
// .h Header of Library
extern MY_API int globalA;
extern MY_API int globalB;
// .cpp Source of Library
int globalA = 1;
int globalB = 2;
>>
MYDATA DoSomething()
{
MYDATA result;
result.valueA = 1;
result.valueB = 2;
return result;
}
I would personally pass a MYDATA into that function, then modify it. This saves the copying on return.
void DoSomething ( MYDATA& result )
{
result.valueA = 1;
result.valueB = 2;
}
But that is just me :)
MYDATA DoSomething()
{
MYDATA result;
result.valueA = 1;
result.valueB = 2;
return result;
}
I would personally pass a MYDATA into that function, then modify it. This saves the copying on return.
void DoSomething ( MYDATA& result )
{
result.valueA = 1;
result.valueB = 2;
}
But that is just me :)
Just wondering. Since you are using _bstr_t, is it a COM-specific solution you need? Maybe even want it to be OLE Automation?
When you have to return multiple values, the only way to do it is to pass a parameter to the function by reference and set the value of that parameter inside the function.