I need to call a function where I have the LPVOID and the number of arguments. Furthermore I know the types and positions of the arguments. The arguments can be of type int, int*, double, double*, string, string*. As the arguments can be in any order the possible list of templates would be very large. The return value is always boolean.
bool Func1(int);
bool Func1(int*);
bool Func1(double);
(...)
bool Func2(int,int);
bool Func2(int,int*);
(...)
So this is not an option. I've tried to use std::tuple but with no success. The following examples only works for a function with arguments (int, double).
template <typename R, typename... Args>
R call(FARPROC fp, Args... args) throw(HRESULT)
{
typedef R(__stdcall * function_pointer)(Args...);
function_pointer P = (function_pointer)fp;
const auto return_value = (*P)(std::forward<Args>(args)...);
().do_cast(fetch_back(args))...);
return return_value;
}
(...)
LPVOID function;
int iVal1 = 2;
double dbVal1 = 3.0;
auto t = std::make_tuple(iVal1 , dbVal1);
bool bRes = call<bool>((FARPROC)function, std::get<0>(t), std::get<1>(t));
What I am thinking about is a generic way of creating the std::tuple based on some input (string etc.), something like: auto t = create_tuple("int,int*,int").

void*?callalways gets inlined (because a particular template sequence only shows up once) and is just a handful of extra lines of assembly, which you needed anyhow!