none
How to create an ActiveX compatible with Enhanced Protected Mode in .NET? RRS feed

  • Question

  • Since my ActiveX control cannot be compatible with EPM, I tried to write two very simple programs in order to check how to create an EPM-Compatible ActiveX in .NET. But the EPM-Compatible ActiveX still cannot be created.

    For convenience I made a sample COM component in C# and an executable file in C++ for registering the component to the AppContainerCompatible category.

    The registration works because AppContainerCompatible category's CLSID appears under the key, Implemented Categories of the sample COM component in the registry. The sample COM component also works when the EPM has been turned off.

    But turning the EPM on will cause "automation server can't create object" error without showing the "Run control" dialog.

    I have searched the Internet, but I cannot find the resources about how to develop the EPM-Compatible ActiveX in .NET.

    Any help would be appreciated.

    The COM component

    namespace MyNamespace
    {
        [ProgId("MyActiveX")]
        [ClassInterface(ClassInterfaceType.AutoDual)]
        [Guid("FF706CF8-4B7E-40AE-88F7-A1FE5C1D1D7A")]
        [ComVisible(true)]
        public class MyActiveX
        {
            [ComVisible(true)]
            public string Init()
            {
                return "OK";
            }
        }
    }
    The registration program
    #include "Windows.h"
    #include "ComCat.h"
    
    const GUID CDECL CATID_AppContainerCompatible = 
    { 0x59fb2056, 0xd625, 0x48d0, { 0xa9, 0x44, 0x1a, 0x85, 0xb5, 0xab, 0x26, 0x40 } }; 
    const GUID CDECL CLSID_MYACTIVEX = 
    { 0xFF706CF8, 0x4B7E, 0x40AE, { 0x88, 0xF7, 0xA1, 0xFE, 0x5C, 0x1D, 0x1D, 0x7A } }; 
    
    HRESULT RegiterClassWithCategory(CLSID ClassId, CATID CategoryId, bool IsRegister = true) { 
        ICatRegister *Registerer = NULL; 
        HRESULT hr = S_OK;
    
        CoInitialize(NULL);
    
        hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
            NULL, 
            CLSCTX_INPROC_SERVER, 
            IID_ICatRegister, 
            (LPVOID*)&Registerer);
    
        if (SUCCEEDED(hr)) { 
            if (IsRegister) { 
                hr = Registerer->RegisterClassImplCategories(ClassId, 1, &CategoryId);
            } 
            else { 
                hr = Registerer->UnRegisterClassImplCategories(ClassId, 1, &CategoryId); 
            }
            Registerer->Release(); 
        }
    
        CoUninitialize();
    
        return hr; 
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        HRESULT hr = S_OK;
        wchar_t buff[100] = {0};
    
        if (argc == 1)
        {
            hr = RegiterClassWithCategory(CLSID_MYACTIVEX, CATID_AppContainerCompatible);
    
            if (SUCCEEDED(hr))
            {
                MessageBox(NULL, L"Registration finished.", L"", MB_OK);
            }
            else
            {
                swprintf_s(buff, 100, L"HRESULT = 0x%x", hr);
                MessageBox(NULL, buff, L"", MB_OK);
            }
        }
        else if (argc == 2 && lstrcmp(argv[1], L"/u") == 0)
        {
            RegiterClassWithCategory(CLSID_MYACTIVEX, CATID_AppContainerCompatible, false);
    
            if (SUCCEEDED(hr))
            {
                MessageBox(NULL, L"Unregistration finished.", L"", MB_OK);
            }
            else
            {
                swprintf_s(buff, 100, L"HRESULT = 0x%x", hr);
                MessageBox(NULL, buff, L"", MB_OK);
            }
        }
        else
        {
            MessageBox(NULL, L"/u - Unregister", L"Invalid paramters", MB_OK);
        }
    
        return 0;
    }


    Friday, April 10, 2015 1:43 AM

All replies

  • Hi,

    Please take a look at this helpful article.

    "To load in EPM on Windows 8, the add-on must also indicate that it is compatible with the AppContainer isolation feature by registering with a COM Component Category that indicates that the component was designed and tested to ensure it runs correctly in the no-read-up process."

    more information : Add-ons in Enhanced Protected Mode

    Best regards,

    Shu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 13, 2015 4:28 PM
  • I've read the article. I'm not sure what a no-read-up process is. My example doesn't read or write anything. I register it with a COM Component Category. But it doesn't work. 
    Tuesday, May 19, 2015 3:36 AM
  • Anybody have a C# version of the registration program above?  TIA
    Monday, June 5, 2017 3:43 PM