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>{}; //SVaPassNext - is generator of structure of any size at compile time. class CVaPassNext{ public: SVaPassNext<50> svapassnext; CVaPassNext(va_list & args){ try{//to avoid access violation 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); } #endifhow 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!
本文介绍了一种在C++中实现将可变参数列表从一个函数传递到另一个函数的方法。通过定义特定的结构体和类,作者创建了一个能够在编译时生成任意大小结构体的解决方案,从而实现在不同函数间传递可变参数的功能。
3796

被折叠的 条评论
为什么被折叠?



