H
He Shiming
Hi All,
In my COM (component object model) server DLL I created, there are these
methods that require buffer allocation. They look like this:
class CComClass : public IClass { // just for demonstration
public:
HRESULT Method (long lParam1, long lParam2, unsigned char* pBufferOut,
long * plSizeOut);
};
To use these methods, I need to call them twice to actually execute the
function. First call, I set pBufferOut to NULL, and the method will return
the size requirement of the buffer in plSizeOut. Using that information, I
proceed with buffer allocation on the client side, and then call the method
again using the allocated buffer pointer. From what I understand, this is a
standard way for these kind of functions.
My problem is, even by using vector<unsigned char> as the buffer, the code
looks very ugly. It requires two calls, and I have to check for errors
before and after allocation. So I wonder if I could create a macro or a
template to automate the two calls, so that it becomes:
vector<unsigned char> buffer;
AUTOFUNC(spCC, Method, lparam1, lparam2, buffer);
There's one catch though, these methods have variable number of arguments.
Only the last two are the same, pBufferOut and plSizeOut. But I'm not sure
how I could use that to my advantage.
Can I put parenthesized arguments into a macro? Can I use templates in this
situation?
Thanks in advance,
In my COM (component object model) server DLL I created, there are these
methods that require buffer allocation. They look like this:
class CComClass : public IClass { // just for demonstration
public:
HRESULT Method (long lParam1, long lParam2, unsigned char* pBufferOut,
long * plSizeOut);
};
To use these methods, I need to call them twice to actually execute the
function. First call, I set pBufferOut to NULL, and the method will return
the size requirement of the buffer in plSizeOut. Using that information, I
proceed with buffer allocation on the client side, and then call the method
again using the allocated buffer pointer. From what I understand, this is a
standard way for these kind of functions.
My problem is, even by using vector<unsigned char> as the buffer, the code
looks very ugly. It requires two calls, and I have to check for errors
before and after allocation. So I wonder if I could create a macro or a
template to automate the two calls, so that it becomes:
vector<unsigned char> buffer;
AUTOFUNC(spCC, Method, lparam1, lparam2, buffer);
There's one catch though, these methods have variable number of arguments.
Only the last two are the same, pBufferOut and plSizeOut. But I'm not sure
how I could use that to my advantage.
Can I put parenthesized arguments into a macro? Can I use templates in this
situation?
Thanks in advance,