locked
CoCreateInstanceFromApp call fails while CoCreateInstance succeeds

    Question

  • In order to pass  the package validation, we're replacing CoCreateInstance() with CoCreateInstanceFromApp(), but we found that:

    hr = CoCreateInstance(CLSID_Location, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&pLocation)); // will succeed
    CoCreateInstanceFromApp() will fail with
    REGDB_E_CLASSNOTREG...

    We did see the remarks for on MSDN, so I guess the class we're tryinng to activate is unsupported.
    The question is: how could we predict CoCreateInstanceFromApp() will fail or not? as I thought CLSID_Location should be a built-in class,
    And what does the 'app container' mean, what are the supporting list for an App Container ?

    Remarks

    The CoCreateInstanceFromApp function is the same as the CoCreateInstanceEx function, with the following differences.

    • The CoCreateInstanceFromApp function reads class registrations only from Fusion contexts and manifests, and from the HKLM\SOFTWARE\Classes\CLSID registry hive.
    • Only built-in classes that are supported in the app container are supplied. Attempts to activate unsupported classes, including all classes installed by 3rd-party code as well as many Windows classes, result in error code REGDB_E_CLASSNOTREG.
    • The CoCreateInstanceFromApp function is available to Metro style apps that are delivered from the Windows Store. Desktop applications can call this function, but they have the same restrictions as apps from the Windows Store
    Sunday, April 8, 2012 5:00 PM

Answers

  • CoCreateInstanceFromApp can create a COM object from a registration-free context included with the app. Metro style apps do not have access to the registry and cannot instantiate COM objects which are declared there. As the underlined section of the docs you quote calls out, REGDB_E_CLASSNOTREG indicates that the CLSID you are trying to load is not available to your Metro style app.

    The App Container is the package your app is delivered in from the store. If you have your own COM dll manifested for registration-free COM then you can deploy it in your App Package and load it with CoCreateInstanceFromApp.

    CLSID_Location is a Windows COM object for the Desktop Location API. It is not available to Metro style apps. Instead, use the Metro style location API from Windows::Devices::Geolocation. See Detecting geolocation.

    --Rob


    Monday, April 9, 2012 9:26 PM
    Owner

All replies

  • Hello,

    Would you please provide us a whole code snippet for this issue?
    Based on these codes we can get more information about this error.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 9, 2012 11:58 AM
  • CoCreateInstanceFromApp can create a COM object from a registration-free context included with the app. Metro style apps do not have access to the registry and cannot instantiate COM objects which are declared there. As the underlined section of the docs you quote calls out, REGDB_E_CLASSNOTREG indicates that the CLSID you are trying to load is not available to your Metro style app.

    The App Container is the package your app is delivered in from the store. If you have your own COM dll manifested for registration-free COM then you can deploy it in your App Package and load it with CoCreateInstanceFromApp.

    CLSID_Location is a Windows COM object for the Desktop Location API. It is not available to Metro style apps. Instead, use the Metro style location API from Windows::Devices::Geolocation. See Detecting geolocation.

    --Rob


    Monday, April 9, 2012 9:26 PM
    Owner