What is the difference between COM property methods and regular interface methods?

James Pack

I have been poking around with WRL at the ABI layer for the last couple of weeks and have run into this problem.

I have an interface defined in IDL as follows:

namespace Async{
[uuid(f469e110-7ef5-41df-a237-9ddef9aed55c), version(1.0)]
interface IDownloader : IInspectable
{
    HRESULT GetFeed([in] HSTRING url,[out, retval] Windows.Web.Syndication.SyndicationFeed ** feed);
    [propget]HRESULT Feed([out, retval]Windows.Web.Syndication.SyndicationFeed ** feed);
}

[version(1.0), activatable(1.0)]
runtimeclass Downloader
{
    [default] interface IDownloader;
}

}

Which I have defined in my header file like so:

#pragma once

#include "Async_h.h"

namespace ABI {
    namespace Async {


    class Downloader : public Microsoft::WRL::RuntimeClass<ABI::Async::IDownloader>
    {
        InspectableClass(L"Async.Downloader", BaseTrust);

    public:
        Downloader();
        STDMETHOD(GetFeed)(HSTRING url, ABI::Windows::Web::Syndication::ISyndicationFeed ** feed);
        STDMETHOD(get_Feed)(ABI::Windows::Web::Syndication::ISyndicationFeed ** feed);

    private:

        //Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Uri> feedUrl;
        Microsoft::WRL::ComPtr<ABI::Windows::Web::Syndication::ISyndicationFeed> m_feed;

    };

    ActivatableClass(Downloader);
}

}

In my cpp file I implement the functions:

    STDMETHODIMP Downloader::GetFeed(HSTRING url, ISyndicationFeed** feed)
    {

        HRESULT hr;
        RoInitializeWrapper ro(RO_INIT_MULTITHREADED);
        ComPtr<IUriRuntimeClass> uri;
        ComPtr<IUriRuntimeClassFactory> uriFactory;
        hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Foundation_Uri).Get(), &uriFactory);
        hr = uriFactory->CreateUri(url, uri.GetAddressOf());

        ComPtr<ISyndicationClient> client;
        ComPtr<IInspectable> inspectable;

        RoActivateInstance(HStringReference(RuntimeClass_Windows_Web_Syndication_SyndicationClient).Get(), &inspectable);

        hr = inspectable.As(&client);
        Event timerCompleted(CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, WRITE_OWNER | EVENT_ALL_ACCESS));
        auto callback = Callback<IAsyncOperationWithProgressCompletedHandler<SyndicationFeed*,RetrievalProgress>>([&](IAsyncOperationWithProgress<SyndicationFeed*,RetrievalProgress> *op, AsyncStatus status) ->HRESULT 
        {
            auto error = GetLastError();
            if (status == AsyncStatus::Completed)
            {
                hr = op->GetResults(m_feed.GetAddressOf());
                *feed = m_feed.Get();

            }


            return S_OK;
        });
        ComPtr<IAsyncOperationWithProgress<SyndicationFeed*,RetrievalProgress>>  operation;
        hr = client->RetrieveFeedAsync(uri.Get(), operation.GetAddressOf());
        operation->put_Completed(callback.Get());
        return S_OK;
    }


    STDMETHODIMP Downloader::get_Feed(ISyndicationFeed** feed)
    {
        *feed = m_feed.Get();
        return S_OK;
    }

The property works as expected it is projected to c++/cx as it should be. However,in the GetFeed method, when I attempt to set the feed parameter to the retrieved feed I get an access violation. Obviously I know that the memory is bad but the way I understand COM properties, they are essentially function calls and the property method and the GetFeed method are doing exactly the same thing minus the retrieval part.

Here are my questions:

  1. What is the difference between COM property methods and regular interface methods in terms of the projected return value if any?
  2. Why is the parameter to the property method initialized to nullptr and the parameter to the GetFeed Method not when they are described exactly the same in IDL?
  3. If the out parameters in property methods are initialized, what part of the COM runtime is doing that for me and is that controllable? IE is there a way to get memory that I can write to passed to me?

I know that I could probably design that away but that is not the point. I am just trying to learn how it all works.

Thanks.

Peter Torr - MSFT

In your lambda you are capturing by reference with [&]. You need to capture the feed parameter by value, since the stack frame is long gone by the time your lambda executes.

The bigger issue is that the client has no idea when they can retrieve the results since you don't provide that information. (I see you create an unused Win32 Event object, so maybe there's some other code to make that work that you've deleted).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the difference between regular and Async methods (OnGet vs OnGetAsync)

From Dev

What is difference between abstract class with all abstract methods and interface(not technically)

From Java

What is the difference between setter methods and constructor methods?

From Java

What is the difference between inherited methods and public methods?

From Java

What is the difference between these two methods

From Dev

what is the difference between these two methods?

From Dev

What is the difference between these awaitable methods?

From Dev

What is the difference between these methods in class

From Dev

Default Interface Methods. What is deep meaningful difference now, between abstract class and interface?

From

What is the difference in calling an interface methods and struct methods in serveHTTP handler?

From Dev

What's the difference between class methods and instance methods in Swift?

From Dev

What's the difference between Custom model manager methods and QuerySet methods?

From Dev

What is difference between global methods and instance methods in Vue.js?

From Dev

what is the difference between a function that returns an object with methods and a variable that is an object with methods

From Dev

What's the difference between ARSession delegate methods?

From Dev

What is the difference between these sending methods in python scapy?

From Dev

What is the difference between JavaScript Object creation methods?

From Java

What is the difference between `finishAffinity();` and `finish()` methods in Android?

From Java

What is the difference between Java intrinsic and native methods?

From Dev

What is the difference between setScrollPosition & getTabAt methods of the TabLayout?

From Dev

What's difference between these generic methods?

From Dev

What's the difference between these namespacing methods?

From Dev

What is the difference between ConfigureWebHostDefaults and ConfigureWebHost methods?

From Dev

What is the difference between Methods and Properties for an object in python?

From Dev

What is the difference between these methods to obtain resource usage?

From

What is the difference between `size` and `length` methods

From Dev

What's the difference between async methods and threads?

From

What is the difference between concurrency, parallelism and asynchronous methods?

From

What is the difference between class and instance methods?

Related Related

  1. 1

    What is the difference between regular and Async methods (OnGet vs OnGetAsync)

  2. 2

    What is difference between abstract class with all abstract methods and interface(not technically)

  3. 3

    What is the difference between setter methods and constructor methods?

  4. 4

    What is the difference between inherited methods and public methods?

  5. 5

    What is the difference between these two methods

  6. 6

    what is the difference between these two methods?

  7. 7

    What is the difference between these awaitable methods?

  8. 8

    What is the difference between these methods in class

  9. 9

    Default Interface Methods. What is deep meaningful difference now, between abstract class and interface?

  10. 10

    What is the difference in calling an interface methods and struct methods in serveHTTP handler?

  11. 11

    What's the difference between class methods and instance methods in Swift?

  12. 12

    What's the difference between Custom model manager methods and QuerySet methods?

  13. 13

    What is difference between global methods and instance methods in Vue.js?

  14. 14

    what is the difference between a function that returns an object with methods and a variable that is an object with methods

  15. 15

    What's the difference between ARSession delegate methods?

  16. 16

    What is the difference between these sending methods in python scapy?

  17. 17

    What is the difference between JavaScript Object creation methods?

  18. 18

    What is the difference between `finishAffinity();` and `finish()` methods in Android?

  19. 19

    What is the difference between Java intrinsic and native methods?

  20. 20

    What is the difference between setScrollPosition & getTabAt methods of the TabLayout?

  21. 21

    What's difference between these generic methods?

  22. 22

    What's the difference between these namespacing methods?

  23. 23

    What is the difference between ConfigureWebHostDefaults and ConfigureWebHost methods?

  24. 24

    What is the difference between Methods and Properties for an object in python?

  25. 25

    What is the difference between these methods to obtain resource usage?

  26. 26

    What is the difference between `size` and `length` methods

  27. 27

    What's the difference between async methods and threads?

  28. 28

    What is the difference between concurrency, parallelism and asynchronous methods?

  29. 29

    What is the difference between class and instance methods?

HotTag

Archive