Posted on 2013-05-18 10:45
S.l.e!ep.¢% 阅读(652)
评论(0) 编辑 收藏 引用 所属分类:
C++
Introduction
I've been looking for solution of passing variable-argument list from my va-function to another one, like TRACE for example. All solutions I saw were about using special functions that take va_list as argument. But this is a un-straight way. Why couldn't I just pass "..." to next function? C++ syntax doesn't allow this. But C++ allows to extend itself. Let me introduce you new macros from va_ set:
template<byte count>
struct SVaPassNext{
SVaPassNext<count-1> big;
DWORD dw;
};
template<> struct SVaPassNext<0>{};
class CVaPassNext{
public:
SVaPassNext<50> svapassnext;
CVaPassNext(va_list & args){
try{
memcpy(&svapassnext, args, sizeof(svapassnext));
} catch (...) {}
}
};
#define va_pass(valist) CVaPassNext(valist).svapassnext#if 0 //using:void MyVA_Function(szFormat, ...){
va_list args;
va_start(args, szFormat);
SomeOtherVA_Function(szFormat, va_pass(args));
va_end(args);
}
#endif
how this works:
I just copy 50 * sizeof(DWORD) bytes of stack to my struct of this size and simply pass this struct as ... argument to next function. Compiler just copies my copy of local stack to next function stack. And that's all we need.
Enjoy!