当我使用WRL创建一个winrt组件时,问题是我只能使用ABI::Windows::xxx
命名空间,并且我无法在WRL中使用Windows::UI::Xaml::Media::Imaging
命名空间。如何使用WRL返回内置winrt组件?
然后,如何创建一个内置的winrt组件作为返回值?
// idl
import "inspectable.idl";
import "Windows.Foundation.idl";
import "Windows.UI.Xaml.Media.Imaging.idl";
namespace Decoder
{
interface IPhotoDecoder;
runtimeclass PhotoDecoder;
interface IPhotoDecoder : IInspectable
{
HRESULT Decode([in] int width, [in] int height, [out, retval] Windows.UI.Xaml.Media.Imaging.BitmapImage **ppBitmapImage);
}
[version(COMPONENT_VERSION), activatable(COMPONENT_VERSION)]
runtimeclass PhotoDecoder
{
[default] interface IPhotoDecoder;
}
}
// cpp
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace ABI::Windows::UI::Xaml::Media::Imaging;
namespace ABI
{
namespace Decoder
{
class PhotoDecoder: public RuntimeClass<IPhotoDecoder>
{
InspectableClass(L"Decoder.PhotoDecoder", BaseTrust)
public:
PhotoDecoder()
{
}
HRESULT __stdcall Decode(_In_ int width, _In_ int height, _Out_ IBitmapImage **ppBitmapImage)
{
// How to create Windows.UI.Xaml.Media.Imaging.BitmapImage without using Windows::UI::Xaml::Media::Imaging
}
};
ActivatableClass(PhotoDecoder);
}
}
非常感谢,但是当从UI线程创建的另一个线程调用ActivateInstance时,它将返回'RPC_E_WRONG_THREAD',并且无法创建实例。但我也尝试从不同线程调用'CreateStreamOverRandomAccessStream',我认为它同样会创建一个COM对象,但它可以很好地工作。你知道为什么吗? – user1713871