Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6560685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:29:32+00:00 2026-05-25T13:29:32+00:00

I have a com method where I want to pass information about 7 days

  • 0

I have a com method where I want to pass information about 7 days of the week encoded in an unsigned long (to represent “selected” hours of the day in the week)

[id(5)]          HRESULT GetSchedule([out, retval] SAFEARRAY(unsigned long)* days);
[id(6)]          HRESULT SetSchedule([in] SAFEARRAY(unsigned long) days);

This is one way to do this but it would not be obvious for the COM client that it has to pass an array of 7 elements, where each element is a day (let alone that ordering could be with first day Monday or Sunday, and is not explicit in the interface).

  • Is there a way to make the size of the input array explicit ?

I know it could still be better to split this in 7 different methods for every day, also

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:29:32+00:00Added an answer on May 25, 2026 at 1:29 pm

    For Dispatch-compatible automation clients, where you have to use use SAFEARRAY’s, this is not possible. SAFEARRAY knows its own size, an can be marshalled safely.

    The best you can do in case of error is to return E_INVALIDARG and set an IErrorInfo describing the issue. Also, mention in your documentation.

    For IUnknown-Binding you could use raw pointers with a size_is declaration for the intreface, but I doubt that owuld improve things.

    edit

    I know it could still be better to split this in 7 different methods for every day, also

    Not necessarily, that would be painful to call in some circumstances.

    There is a race condition with other clients trying to change a single value, you may need to take provisions for that.


    You could also set it up as an indexed property (i.e. a propget / propput method that takes an addiitonal “weekday” parameter). Again, you would have to validate that the weekday parameter is in the valid range.

    This would be a bit more obvious as interface, IMO, but if the object could be remote, a method to set all weekdays at once with a single server roundtrip is always welcome.


    edit The MSDN page even recommends to use the fixed size for arrays, like this:

    // MIDL:
    HRESULT SetWeekdayNames([in] BSTR valNames[8]);
    

    instead of the size_is variant:

    HRESULT SetWeekdayNames([in, size_is(8)] BSTR * valNames);
    

    The respective C++ declaration would probably be

    HRESULT SetWeekdayNames(BSTR * valNames);
    

    in both cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a COM interface with a following method definition (IDL notation): SCODE GetText( [in,
We have a COM object implemented with C++/ATL that includes a method which will
Setup: I have a COM DLL that calls a method inside a managed C#
I have a COM interface and need to add an accessor method to it.
I have created a .NET DLL which makes some methods COM visible. One method
I have this code working in C#: var request = (HttpWebRequest)WebRequest.Create(https://x.com/service); request.Method = GET;
I want to pass a varying number of parameters between two objects. I have
I have the following scenario: I want to pass a parameter to a page
I have a method that I want to be transactional in the abstract sense.
i have done as Vdex suggested here: https://stackoverflow.com/a/5801502/973485 And used the RenderPartialToString method he

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.