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

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;
}



April 7th, 2015 11:31pm

Hi lzhangwdk,

Regarding to development question, our help would be limited and we suggest you post your issue to MSDN .NET forum for software development because you might get more useful advices.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=netdevelopment

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

Regards,

D. Wu

Free Windows Admin Tool Kit Click here and download it now
April 9th, 2015 4:15am

Hi Deason Wu

Thank you for your advice.

I've submitted the same question on the Internet Explorer Extension Development forum. I'd like to close this one. Could you help me?

April 9th, 2015 9:54pm

Hi lzhangwdk,

Thanks for your reply and certainly glad to help.

I will close this thread for you soon.

Regards,

D. Wu 

Free Windows Admin Tool Kit Click here and download it now
April 10th, 2015 4:06am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics