lunadev-9461 avatar image
0 Votes"
lunadev-9461 asked FayWang-MSFT commented

[C++/WinRT] load C++/WinRT dll without application manifest

I'm writing a dll and using Windows Vision Skill (C++/WinRT) to process image. Since Windows Skill (C++/WinRT) need application manifest to load its DLL, unfortunately I don't have permission to edit application manifest, my DLL is loaded automatically by system process. 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, but nothing changed.

Here is the code I use to start create object via wrapper, the below code is executed when my dll is attached:

 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)
         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);
         m_error = buf;
     return err;

Here is the manifest file and all DLLs are put into same directory:

 <?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="" ></assemblyIdentity>
       <assemblyIdentity type="win32" name="Microsoft.AI.Skills.SkillInterfacePreview" version=""></assemblyIdentity>
       <assemblyIdentity type="win32" name="Microsoft.AI.Skills.Vision.ObjectDetectorPreview" version=""></assemblyIdentity>

I think the problem is the Windows Skill (C++/WinRT) DLL cannot be loaded, so I cannot create the object.

Does anyone know how to load C++/WinRT inside other dll without modifying application manifest? Please help me.

· 15
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Have you read any tutorial about how to use Windows Vision Skill (C++/WinRT)? Did you read this document? It seems to mention how to create a manifest file.

0 Votes 0 ·

Hi FayWang-MSFT,

Yes, I read it. I followed the tutorial and tried to make an application, it worked fine.
This time, I integrate Windows Vision Skill (C++/WinRT) with Device MFT DLL, unfortunately I got the exception "ClassFactory cannot supply requested class".
Since the Device MFT DLL is loaded by Windows Camera Frame Server, so maybe the manifest of Device MFT cannot be loaded correctly, or just because C++/WinRT cannot be used inside Device MFT DLL (I'm not familiar with C++/WinRT).

0 Votes 0 ·

CLASS_E_CLASSNOTAVAILABLE is generally returned by DllGetClassObject/DllGetActivationFactory to indicate that the DLL doesn’t recognize that CLSID/ACID. This failure should generally be past the point where reg-free WinRT is affecting the activation. Reg-free WinRT is primarily about mapping the CLSID/ACID onto a DLL. In this case, we’ve succeeded in mapping onto a DLL, and we’ve loaded that DLL. Possible explanations: it’s the wrong DLL (or possibly the wrong DLL version), or the DLL is incorrectly implemented.

0 Votes 0 ·

Hi, have you solved your issue? Do you have other questions?

0 Votes 0 ·

Hi, is there any update?

0 Votes 0 ·

I haven't heard from you for a while. Have you solved your issue?

0 Votes 0 ·
Show more comments

0 Answers