K
K
Kvert0072014-02-28 13:47:42
C++ / C#
Kvert007, 2014-02-28 13:47:42

Return 3 variables from a C++ function

Hello! I am writing a DLL in C++ which includes several functions. Further this library will cling to the project on Visual Basic. Now the function returns a string of type BSTR, but new requirements have arrived, now it is necessary for the function to return a string + processing code (int type variable) + error code if it did not work out. How to make all three variables returned???

Answer the question

In order to leave comments, you need to log in

12 answer(s)
V
v_prom, 2014-02-28
@v_prom

pack them into a structure or an object.

M
Mikhail Doshevsky, 2014-02-28
@MikhailD

There are several options.
You have already been told about one - to make a structure with the necessary fields and return it.
The second is to pass pointers to pointers into the function and return values ​​through arguments.
The third is to make some additional functions, such as GetLastErrorCode(), that will return error codes or something else.
You can somehow combine these methods, the specific implementation depends on the task.

K
Kvert007, 2014-02-28
@Kvert007

And in VB it is possible to transfer structure? If yes that as?

F
Fat Lorrie, 2014-02-28
@Free_ze

support.microsoft.com/kb/187912/en

A
AxisPod, 2014-02-28
@AxisPod

I have no idea how VB works, I never used it, but as an option to return information about an object, then you can work with this object to implement several functions that, based on information about the object, will return the desired value, and also delete it when no longer required.

K
Kvert007, 2014-02-28
@Kvert007

The library is written in VS 2005 so that it can be used in xp and win2000. Pair is also a structure....
Interested then how to declare a function???
now like this: extern "C" __declspec(dllexport) BSTR CCONV getDomainUserSAMAccountName
How to declare it in VB?? currently declared like this:
Private Declare Function sAMAccountName Lib "FinalLib.dll" Alias ​​"[email protected]" () As String

K
Kvert007, 2014-02-28
@Kvert007

To shove it all into an object, you need to write a class, but there are only functions.
1) Returns the value of samacauntname from hell
2) Returns the value of UPN from AD
3) List of user groups.

K
Kvert007, 2014-02-28
@Kvert007

Help!!!

I
Ivan Starkov, 2014-02-28
@icelaba

see boost namely boost::tuple
return boost::make_tuple(a,b,c)

K
Kvert007, 2014-03-03
@Kvert007

Maybe I'm dumb of course, but if you do this in WB...
Private Declare Function test Lib "FinalLib.dll" Alias ​​"[email protected]" (ByRef i As Integer)
then a reference to the variable i is passed as in C ++ to accept and write new value in this region. memory

K
Kvert007, 2014-03-03
@Kvert007

UP!!!

O
Oleg Ilyushin, 2014-03-05
@zmeykas

If it's absolutely crutch - return a string in which three of your variables are separated by some character (character set), and parse it back in BASIC.
For example: [processing code]\t[error code]\t[string]
But it is better, of course, to pass pointers to variables into the function in which the result will be stored.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question