locked
Can I call C++/WinRT inside Device MFT? RRS feed

  • Question

  • I'm writing Device MFT and using Windows Vision Skill to process image. I had the problem when integrating Windows Vision Skill into Device MFT. Since Windows Vision Skill is C++/WinRT, so I think the problem is about how to integrate C++/WinRT code with Device MFT.

    Here is what I did:

    Create C++ DLL wrapper for Windows Skill (C++/WinRT) and then import to Device MFT.  I got the error "ClassFactory cannot supply requested class" when creating C++/WinRT object.

    I also tried to use Activation Context API to activate the context, this time the camera stop working.

    Here is the code I use to start create object via wrapper:

        Wrapper* pwrap = new Wrapper();
    
        ACTCTX actCtx;
        memset((void*)&actCtx, 0, sizeof(ACTCTX));
        actCtx.cbSize = sizeof(ACTCTX);
        actCtx.lpSource = PathToManifest(); 
    
        HANDLE hCtx = ::CreateActCtx(&actCtx);
        if (hCtx == INVALID_HANDLE_VALUE)
            DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "CreateActCtx returned: INVALID_HANDLE_VALUE");
        else
        {
            ULONG_PTR cookie;
            if (::ActivateActCtx(hCtx, &cookie))
            {
    
                S_Error err_res = pwrap->Create();
    
                ::DeactivateActCtx(0, cookie);
            }
        }

    Here is the c++/winrt creating code:

    bool Wrapper::Create()
    {
        bool err = false;
    
        try {
    
            // Create the ObjectDetector skill descriptor
            auto skillDescriptor = ObjectDetectorDescriptor().as<ISkillDescriptor>();
    
            // Create instance of the skill
            ObjectDetectorSkill Skill = skillDescriptor.CreateSkillAsync().get().as<ObjectDetectorSkill>();
    
            // Create instance of the skill binding
            ObjectDetectorBinding Binding = Skill.CreateSkillBindingAsync().get().as<ObjectDetectorBinding>();
    
            err = true;
        }
        catch (hresult_error const& ex)
        {
            std::wstring wbuf = ex.message().c_str();
            int wleng = wbuf.length();
            char* buf = new char[wleng];
            size_t len;
            errno_t  error = wcstombs_s(&len, (char*)(buf), 255, wbuf.c_str(), 255);
            UNREFERENCED_PARAMETER(len);
            UNREFERENCED_PARAMETER(error);
    
            m_error = buf;
        }
    
        return err;
    }

    Here is the manifest file and all the dependency DLL are put into same directory with MFT dll:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
      <assemblyIdentity type="win32" name="Wrapper" version="1.0.0.0" ></assemblyIdentity>
        <dependency>
        <dependentAssembly>
          <assemblyIdentity type="win32" name="Microsoft.AI.Skills.SkillInterfacePreview" version="1.0.0.0"></assemblyIdentity>
        </dependentAssembly>
      </dependency>
    
      <dependency>
        <dependentAssembly>
          <assemblyIdentity type="win32" name="Microsoft.AI.Skills.Vision.ObjectDetectorPreview" version="1.0.0.0"></assemblyIdentity>
        </dependentAssembly>
      </dependency>
    </assembly>

    I think there are 2 problems here:

    1. The Windows Skill (C++/WinRT) DLL cannot be loaded, so I cannot create the object.

    2. I'm not sure that calling Async function inside MFT would be OK or not, since the camera stopped working when using Activation Context API (I assume that the Activation Context API help loading all dependency DLL).

    Does anyone know how to integrate C++/WinRT with MFT? Please help me.

    Wednesday, March 11, 2020 5:15 PM

All replies

  • Hi,

    This forum is for "Discuss windows desktop development issue." It is Win32 C++ focused.

    For C++/WinRT related issue you can ask a question at Microsoft Q&A for more professional support.

    Best Regards,

    Drake


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 13, 2020 1:30 AM