Link to home
Start Free TrialLog in
Avatar of hp746
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
Avatar of HooKooDooKu
HooKooDooKu

It's only possible to return one variable value.

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.
ASKER CERTIFIED SOLUTION
Avatar of numberkruncher
numberkruncher
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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;
>>

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?