CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2000
    Posts
    10

    Angry 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

  2. #2
    Join Date
    May 2002
    Location
    Russia
    Posts
    1,571
    see vararg attribute

  3. #3
    Join Date
    Sep 2002
    Posts
    77
    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).

  4. #4
    Join Date
    Dec 2000
    Posts
    10

    Thanks for the answering.....

    Is it really no other way to do it??

  5. #5
    Join Date
    Feb 2000
    Posts
    101
    why not use XML? Use a single BSTR and just pass in the XML the various arguments you need.

  6. #6
    Join Date
    Dec 2000
    Posts
    10

    Lightbulb 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??

  7. #7
    Join Date
    Sep 2002
    Posts
    77
    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.

  8. #8
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    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.

  9. #9
    Join Date
    Dec 2000
    Posts
    10

    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
  •  





Click Here to Expand Forum to Full Width

Featured