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