|
-
October 23rd, 2002, 08:48 AM
#1
va_list in COM??
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
-
October 23rd, 2002, 08:56 AM
#2
-
October 23rd, 2002, 02:40 PM
#3
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).
-
October 24th, 2002, 07:00 AM
#4
Thanks for the answering.....
Is it really no other way to do it??
-
October 24th, 2002, 07:06 AM
#5
why not use XML? Use a single BSTR and just pass in the XML the various arguments you need.
-
October 24th, 2002, 10:52 AM
#6
XML?
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??
-
October 24th, 2002, 02:27 PM
#7
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.
-
October 24th, 2002, 02:40 PM
#8
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).
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.
-
October 25th, 2002, 06:27 AM
#9
thanks guys
i would like to try them out first.
Last edited by leonwoo; October 25th, 2002 at 06:29 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|