Hi,
Is it possible to develop a COM function that receives variable arguments? I have been cracking my head for sometimes to figure out how to do it....Please provide a small example.
thanks.
John Woo
Printable View
Hi,
Is it possible to develop a COM function that receives variable arguments? I have been cracking my head for sometimes to figure out how to do it....Please provide a small example.
thanks.
John Woo
see vararg attribute
I'm quite sure that it is impossible to have a variable number of arguments in COM the same way as in C/C++. va_list / the ellipsis is a C/C++ specific construct and COM is a binary standard which supports other languages (and where this feature is unavailable).
If you have a fixed number of arguments but some of them may be ommited then have a look at optional parameters or defaultvalue.
What is very close to a variable number of arguments is the SAFEARRAY. I think you can also build a SAFEARRAY of VARIANTs to have different data types but I'm not sure (my MSDN library is down at the moment so I can't prove).
Is it really no other way to do it??
why not use XML? Use a single BSTR and just pass in the XML the various arguments you need.
thanks for the fresh idea..
you are right.......but how to do that?
I have never done XML using VC before. Is there an article showing how to do it??
I like to use a freeware XML parser and generator named CMarkup (look at www.firstobject.com). It is a C++ implementation - very fast, easy to use and comes with some samples.
If you want to have a full featured XML parser use msxml2/3.dll.
But if you want to go such a way there is another easy solution: build a - for example - tab-delimited BSTR.
Yes, it's true that you can pass a SafeArray with VARIANTs and make them all a different type. I would call it sort of an intermediate solution between the tab-delimited BSTR and the XML solution. With the SafeArray you can also pass along type information which is useful, but you can't easily specify which value corresponds to which parameter, so both sides would have to agree on that beforehand.Quote:
Originally posted by alpha137
What is very close to a variable number of arguments is the SAFEARRAY. I think you can also build a SAFEARRAY of VARIANTs to have different data types but I'm not sure (my MSDN library is down at the moment so I can't prove).
i would like to try them out first.:p