1

IDL で Windows ランタイム型を定義し、その投影型を使用しようとしていました。デフォルトで生成された空のアプリUWP プロジェクト ( 「空のアプリ」と呼ばれる) から、 「MyControl.idl」を追加しました。

namespace BlankApp
{
    [default_interface]
    runtimeclass MyControl : Windows.UI.Xaml.Controls.Control
    {
        MyControl();
    }
}

ソリューションをコンパイルし、MyControl.hMyControl.cppGenerated Files/sourcesからプロジェクトのルート ディレクトリにコピーしました。

投影された型のヘッダーを含め、次のコードを に追加しましたApp::OnLaunched

#include <winrt/BlankApp.h>

...

void App::OnLaunched(LaunchActivatedEventArgs const& e)
{
    auto const myControl{ winrt::BlankApp::MyControl() };
    ...

これはすべてコンパイルされ、リンクされています。実行時に、hresult_error(0x80040154: REGDB_E_CLASSNOTREG クラスが登録されていません) をスローします。

例外が発生した時点でのコールスタックの先頭は次のようになります。

BlankApp.exe!winrt::hresult_error::hresult_error(const HRESULT code=REGDB_E_CLASSNOTREG Class not registered, winrt::hresult_error::from_abi_t __formal={...}) Line 2977  C++ Symbols loaded.
BlankApp.exe!winrt::throw_hresult(const HRESULT result=REGDB_E_CLASSNOTREG Class not registered) Line 3211  C++ Symbols loaded.
BlankApp.exe!winrt::check_hresult(HRESULT result=REGDB_E_CLASSNOTREG Class not registered) Line 3261    C++ Symbols loaded.
BlankApp.exe!winrt::impl::get_activation_factory<winrt::BlankApp::MyControl,winrt::Windows::Foundation::IActivationFactory>() Line 7375 C++ Symbols loaded.
BlankApp.exe!winrt::impl::factory_cache_entry<winrt::BlankApp::MyControl,winrt::Windows::Foundation::IActivationFactory>::get() Line 7448   C++ Symbols loaded.
BlankApp.exe!winrt::get_activation_factory<winrt::BlankApp::MyControl,winrt::Windows::Foundation::IActivationFactory>() Line 7520   C++ Symbols loaded.
BlankApp.exe!winrt::BlankApp::MyControl::MyControl() Line 74    C++ Symbols loaded.
BlankApp.exe!winrt::BlankApp::implementation::App::OnLaunched(const winrt::Windows::ApplicationModel::Activation::LaunchActivatedEventArgs & e={...}) Line 50   C++ Symbols loaded.

module.g.cppはアプリケーションにコンパイルされ、次のコードが含まれています。

HRESULT __stdcall WINRT_GetActivationFactory(HSTRING classId, void** factory)
{
    try
    {
        *factory = nullptr;
        wchar_t const* const name = WindowsGetStringRawBuffer(classId, nullptr);

        if (0 == wcscmp(name, L"BlankApp.MainPage"))
        {
            *factory = winrt::detach_abi(winrt::make<winrt::BlankApp::factory_implementation::MainPage>());
            return S_OK;
        }

        if (0 == wcscmp(name, L"BlankApp.MyControl"))
        {
            *factory = winrt::detach_abi(winrt::make<winrt::BlankApp::factory_implementation::MyControl>());
            return S_OK;
        }

#ifdef _WRL_MODULE_H_
        return ::Microsoft::WRL::Module<::Microsoft::WRL::InProc>::GetModule().GetActivationFactory(classId, reinterpret_cast<::IActivationFactory**>(factory));
#else
        return winrt::hresult_class_not_available().to_abi();
#endif
    }
    catch (...)
    {
        return winrt::to_hresult();
    }
}

どうやら、すべてが必要な場所にあるように見えますが、私の型は Windows ランタイムによる参照用に登録されていませんでした。見逃している登録手順はありますか? それとも、これは Windows ランタイム コンポーネントではなく、UWP アプリケーションからもサポートされていますか?

4

1 に答える 1