Answer the question
In order to leave comments, you need to log in
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
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.
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.
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
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.
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
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 questionAsk a Question
731 491 924 answers to any question