BlueTrin
BlueTrin

Reputation: 10063

How can I return multiple values in a DLL-safe way in C++?

I would like to return multiple values in a cross DLL-safe way in C++.

Should I use a stuct/class ?

Upvotes: 1

Views: 895

Answers (2)

Aamir
Aamir

Reputation: 15566

Although your question is not very clear however, here are a few hints:

  1. A class/struct is meant to group things. Although a struct meant for grouping all the return values can be made but it really depends on how closely related those return values are. This is more a matter of adhering to conventions and OOP principals.

  2. To return multiple values, you can use pointers and references. e.g., following function prototype returns a bool in a conventional way but accepts two pointers as parameters. The objects to which these pointers point to can be changed in the callee function and hence, multiple values can be returned.

Function Prototype:

bool returnValues(int i, char* c, int* result);

Upvotes: 2

Naszta
Naszta

Reputation: 7744

Use PIMPL idioms:

In header (dll safe surface):

class Type;

class MyClass
{
public:
  int GetNumberOfType();
  Type * GetValue(int i) { return this->values[i]; };
protected:
  Type ** values;
};

In Source:

#include <Type.h> // common header to real definition and declaration

Upvotes: 0

Related Questions