Exemplo n.º 1
0
// @pymethod |PyICatRegister|UnRegisterClassReqCategories|Unregisters the class as requiring one or more component categories.
PyObject *PyICatRegister::UnRegisterClassReqCategories(PyObject *self, PyObject *args)
{
    PyObject *obCLSID, *obCatIds;
    if ( !PyArg_ParseTuple(args, "OO:UnRegisterClassReqCategories",
                           &obCLSID, // @pyparm <o PyIID>|clsid||Class ID of the relevent class
                           &obCatIds) ) // @pyparm [<o PyIID>, ...]|[catId, ...]||A sequence of category IDs to be unregistered for the class.
        return NULL;

    ICatRegister *pICR = GetI(self);
    if ( pICR == NULL )
        return NULL;

    CLSID clsid;
    if (!PyWinObject_AsIID(obCLSID, &clsid)) {
        PyErr_SetString(PyExc_TypeError, "CLSID is not valid");
        return NULL;
    }

    CATID *pids;
    UINT numIds;
    if (!CATIDsFromPyObject(obCatIds, &pids, &numIds))
        return NULL;

    PY_INTERFACE_PRECALL;
    HRESULT hr = pICR->UnRegisterClassReqCategories(clsid, numIds, pids);
    PY_INTERFACE_POSTCALL;

    DeleteCATIDs(pids);
    if ( FAILED(hr) )
        return PyCom_BuildPyException(hr, pICR, IID_ICatRegister);

    Py_INCREF(Py_None);
    return Py_None;
}
HRESULT RegisterCategory()
{
    HRESULT hresult;
    ICatRegister *pCatRegister;
    CATID usedCategoryIds[1];
    CATEGORYINFO categoryInfo[1];
    
    hresult = CoCreateInstance(CLSID_StdComponentCategoriesMgr,0,CLSCTX_ALL,
        IID_ICatRegister,(void**) &pCatRegister);
    if (SUCCEEDED(hresult)) {
        categoryInfo[0].catid = CATID_4ControlProjectWizard; 
        categoryInfo[0].lcid = MAKELCID(
            MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),SORT_DEFAULT);
        wcscpy(categoryInfo[0].szDescription,OLESTR("4ControlProjectWizardCategory"));
        hresult = pCatRegister->RegisterCategories(
            sizeof(categoryInfo)/sizeof(*categoryInfo),categoryInfo);
        if (SUCCEEDED(hresult)) {
            usedCategoryIds[0] = CATID_4ControlProjectWizard;
            hresult = pCatRegister->RegisterClassImplCategories(
                CLSID_WizardComObj,
                sizeof(usedCategoryIds)/sizeof(*usedCategoryIds),
                usedCategoryIds);
        }
        pCatRegister->Release();
    }
    return hresult;
}
Exemplo n.º 3
0
// @pymethod |PyICatRegister|UnregisterCategories|Unregister one or more previously registered categories.
PyObject *PyICatRegister::UnRegisterCategories(PyObject *self, PyObject *args)
{
    PyObject *obCatIds;
    // @pyparm [<o PyIID>, ...]|[catId, ...]||The list of category IDs to be unregistered.
    if ( !PyArg_ParseTuple(args, "O:UnRegisterCategories", &obCatIds) )
        return NULL;

    ICatRegister *pICR = GetI(self);
    if ( pICR == NULL )
        return NULL;

    CATID *pids;
    UINT numIds;
    if (!CATIDsFromPyObject(obCatIds, &pids, &numIds))
        return NULL;

    PY_INTERFACE_PRECALL;
    HRESULT hr = pICR->UnRegisterCategories( numIds, pids );
    PY_INTERFACE_POSTCALL;

    DeleteCATIDs(pids);

    if ( FAILED(hr) )
        return PyCom_BuildPyException(hr, pICR, IID_ICatRegister);

    Py_INCREF(Py_None);
    return Py_None;
}
Exemplo n.º 4
0
HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
{
	
	// Register your component categories information.
    ICatRegister* pcr = NULL ;
    HRESULT hr = S_OK ;
    hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
                               NULL,
                               CLSCTX_INPROC_SERVER,
                               IID_ICatRegister,
                               (void**)&pcr);
	
	if (SUCCEEDED(hr))
    {
		// Register this category as being "implemented" by
        // the class.
		
		CATID rgcatid[1] ;
        rgcatid[0] = catid;
        hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
    }
	
	if (pcr != NULL)
		pcr->Release();
	return hr;
}
// 注册组件种类为安全
HRESULT AddCategorySafty(CATID catid, WCHAR* catDescription)
{
	ICatRegister* pcr = NULL ;
	HRESULT hr = S_OK ;

	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
		NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
	if (FAILED(hr))
		return hr;

	CATEGORYINFO catinfo;
	catinfo.catid = catid;
	catinfo.lcid = 0x0409 ; // 英语语言

	// 最长只拷贝127个字符。
	size_t len = wcslen(catDescription);
	if (len > 127)
	{
		len = 127;
	}
	wcsncpy_s(catinfo.szDescription, catDescription, len); 
	// Make sure the description is null terminated. 
	catinfo.szDescription[len] = '\0'; 

	//lstrcpyn((TCHAR*)(catinfo.szDescription), catDescription, len+1);

	hr = pcr->RegisterCategories(1, &catinfo);
	pcr->Release();

	return hr;
}
Exemplo n.º 6
0
BOOL
RegisterComCat(CLSID clsid, CATID CatID, BOOL reg)
{
  ICatRegister   *pcr;
  HRESULT        hr = S_OK ;

  CoInitialize(NULL);

  hr = CoCreateInstance(  CLSID_StdComponentCategoriesMgr,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_ICatRegister,
                          (LPVOID*)&pcr);

  if (SUCCEEDED(hr))
    {
      if (reg)
        {
          hr = pcr->RegisterClassImplCategories(clsid, 1, &CatID);
        }
      else
        {
          hr = pcr->UnRegisterClassImplCategories(clsid, 1, &CatID);
        }

      pcr->Release();
    }

  CoUninitialize();

  return SUCCEEDED(hr);
}
Exemplo n.º 7
0
// Helper function to create a component category and associated description
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
{

    ICatRegister* pcr = NULL ;
    HRESULT hr = S_OK ;

    hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
                          NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
    if (FAILED(hr))
        return hr;

    // Make sure the HKCR\Component Categories\{..catid...}
    // key is registered
    CATEGORYINFO catinfo;
    catinfo.catid = catid;
    catinfo.lcid = 0x0409 ; // english

    // Make sure the provided description is not too long.
    // Only copy the first 127 characters if it is
    int len = wcslen(catDescription);
    if (len>127)
        len = 127;
    wcsncpy(catinfo.szDescription, catDescription, len);
    // Make sure the description is null terminated
    catinfo.szDescription[len] = '\0';

    hr = pcr->RegisterCategories(1, &catinfo);
    pcr->Release();

    return hr;
}
Exemplo n.º 8
0
// @pymethod |PyICatRegister|RegisterCategories|Registers one or more component categories. Each component category consists of a CATID and a list of locale-dependent description strings.
PyObject *PyICatRegister::RegisterCategories(PyObject *self, PyObject *args)
{
    PyObject *obCatList;
    // @pyparm [ (<o PyIID>, int, string), ...]|[ (catId, lcid, description), ...]||A sequence of category descriptions.
    if ( !PyArg_ParseTuple(args, "O:RegisterCategories", &obCatList) )
        return NULL;

    ICatRegister *pICR = GetI(self);
    if ( pICR == NULL )
        return NULL;

    if (!PySequence_Check(obCatList)) {
        PyErr_SetString(PyExc_TypeError, "Argument must be a list of CATEGORYINFO tuples");
        return NULL;
    }
    Py_ssize_t noInfos = PyObject_Length(obCatList);
    CATEGORYINFO *infos = new CATEGORYINFO [noInfos];
    if (infos==NULL) {
        PyErr_SetString(PyExc_MemoryError, "Allocating CATEGORYINFO array");
        return NULL;
    }
    for (Py_ssize_t i=0; i<noInfos; i++) {
        PyObject *obCatId;
        PyObject *obThis = PySequence_GetItem(obCatList, i);
        if (obThis==NULL) return NULL;
        BOOL ok = TRUE;
        PyObject *obDesc;
        if (!PyArg_ParseTuple(obThis, "OlO", &obCatId, (long *)&infos[i].lcid, &obDesc)) {
            Py_DECREF(obThis);
            PyErr_SetString(PyExc_TypeError, "Category infos must be CATID, lcid, description");
            delete [] infos;
            return NULL;
        }
        Py_DECREF(obThis);
        if (!PyWinObject_AsIID(obCatId, &infos[i].catid)) {
            delete [] infos;
            return NULL;
        }
        OLECHAR *oc;
        if (!PyWinObject_AsWCHAR(obDesc, &oc, FALSE)) {
            delete [] infos;
            return NULL;
        }
        wcsncpy(infos[i].szDescription, oc,
                sizeof(infos->szDescription)/sizeof(infos->szDescription[0]));
        PyWinObject_FreeWCHAR(oc);
    }

    PY_INTERFACE_PRECALL;
    HRESULT hr = pICR->RegisterCategories(PyWin_SAFE_DOWNCAST(noInfos, Py_ssize_t, ULONG),
                                          infos);
    PY_INTERFACE_POSTCALL;
    delete [] infos;
    if ( FAILED(hr) )
        return PyCom_BuildPyException(hr, pICR, IID_ICatRegister);
    Py_INCREF(Py_None);
    return Py_None;
}
HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid) {
	ICatRegister* pcr = NULL ;
	HRESULT hr = S_OK ;
	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
	if (SUCCEEDED(hr)) {
		CATID rgcatid[1] ;
		rgcatid[0] = catid;
		hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
	}

	if (pcr != NULL)
		pcr->Release();

	return hr;
}
//移除已经注册为安全的组件种类
HRESULT RemoveCategorySafty(CATID catid)
{
	ICatRegister* pcr = NULL ;
	HRESULT hr = S_OK ;

	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
		NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
	if (FAILED(hr))
		return hr;

	hr = pcr->UnRegisterCategories(1, &catid);
	pcr->Release();

	return hr;
}
HRESULT UnregisterCategory()
{
    HRESULT hresult;
    ICatRegister *pCatRegister;
    CATID usedCategoryIds[1];
    
    hresult = CoCreateInstance(CLSID_StdComponentCategoriesMgr,0,CLSCTX_ALL,
        IID_ICatRegister,(void**) &pCatRegister);
    if (SUCCEEDED(hresult)) {
        usedCategoryIds[0] = CATID_4ControlProjectWizard;
        hresult = pCatRegister->UnRegisterClassImplCategories(CLSID_WizardComObj,
            sizeof(usedCategoryIds)/sizeof(*usedCategoryIds),usedCategoryIds);
        pCatRegister->Release();
    }
    return hresult;
}
Exemplo n.º 12
0
//
// DllUnregisterServer
//
// Unregister the COM objects (the tracker and the property page).
// Also remove the tracker from the "Video Trackers" component category.
STDAPI DllUnregisterServer()
{
    HRESULT hr = AMovieDllRegisterServer2( FALSE );
    if (FAILED(hr))
        return hr;

    ICatRegister *reg;
    hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_ALL, IID_ICatRegister, (void **)&reg);
    if (FAILED(hr))
        return hr;

    reg->UnRegisterClassImplCategories(CLSID_CamShiftTracker, 1, const_cast<GUID *>(&CATID_Trackers));

    reg->Release();

    return NOERROR;
} // DllUnregisterServer
Exemplo n.º 13
0
HRESULT OPCEngine::registerServer(void)
{ 
	_TRACE(TL_INF, TG_ENG, (_T("register server")));
	HRESULT res;

	// register COM Server object
	res = _Module.RegisterServer(FALSE);

	if (SUCCEEDED(res))
	{
		ICatRegister *cr;
		CATEGORYINFO catInfo[4];
		CATID catIDs[2];

		if (SUCCEEDED(res = ::CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
			NULL, CLSCTX_ALL, IID_ICatRegister, (void **)&cr)))
		{
			// register category
			catInfo[0].catid = CATID_OPCDAServer10;
			catInfo[1].catid = CATID_OPCDAServer10;
			catInfo[2].catid = CATID_OPCDAServer20;
			catInfo[3].catid = CATID_OPCDAServer20;
			catInfo[0].lcid = MAKELCID( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) , SORT_DEFAULT);
			catInfo[1].lcid = MAKELCID( MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN),  SORT_DEFAULT);
			catInfo[2].lcid = MAKELCID( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) , SORT_DEFAULT);
			catInfo[3].lcid = MAKELCID( MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN),  SORT_DEFAULT);
			wcscpy(catInfo[0].szDescription, L"OPC Data Access Server V1.0A");
			wcscpy(catInfo[1].szDescription, L"OPC Daten Server V1.0A");
			wcscpy(catInfo[2].szDescription, L"OPC Data Access Server V2.0");
			wcscpy(catInfo[3].szDescription, L"OPC Daten Server V2.0");
			res = cr->RegisterCategories(4, catInfo);
			_TRACE(TL_INF, TG_ENG, (_T("register component categories [0x%X]"), res));

			// register server in categories
			catIDs[0] = CATID_OPCDAServer10;
			catIDs[1] = CATID_OPCDAServer20;
			res = cr->RegisterClassImplCategories(g_clsid, 2, catIDs);
			_TRACE(TL_INF, TG_ENG, (_T("register component implementations [0x%X]"), res));

			cr->Release();
		}
	}
	return res; 
} // registerServer
Exemplo n.º 14
0
//创建Component Categories中的初始化安全和脚本安全项  
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)  
{  
    ICatRegister *pcr = NULL ;  
    HRESULT hr = S_OK ;  
    hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,   
            NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);  
    if (FAILED(hr))  
        return hr;  
  
    // 确认HKCR\Component Categories\{..catid...}键值被注册  
    CATEGORYINFO catinfo;  
    catinfo.catid = catid;  
    catinfo.lcid = 0x0409; // english  
    //size_t len;  
    // 确认描述不是太长。  
    // 只复制开始的127个字符。  
    // StringCchLength的第二个参数表示被读入catDescription的最大字符数。  
    // 第三个参数表示字符串的长度  
    //hr = StringCchLength(catDescription, STRSAFE_MAX_CCH, &len);  
    int len = wcslen(catDescription);  
    if (SUCCEEDED(hr))  
    {  
        if (len>127)  
        {  
            len = 127;  
        }  
    }     
    else  
    {  
        // TODO: Write an error handler;  
    }  
  
    wcsncpy(catinfo.szDescription, catDescription, len);  
    //hr = StringCchCopy(catinfo.szDescription, len + 1, catDescription);  
    // 添加字符串结束符.  
    //catinfo.szDescription[len + 1] = '\0';  
    catinfo.szDescription[len] = '/0';  
  
    hr = pcr->RegisterCategories(1, &catinfo);  
    pcr->Release();  
    return hr;  
}  
Exemplo n.º 15
0
HRESULT RegisterComCat()
{
    CoInitialize(NULL);

    ICatRegister *pcr;
    HRESULT hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
                                  NULL, 
                                  CLSCTX_INPROC_SERVER, 
                                  IID_PPV_ARGS(&pcr));
    if (SUCCEEDED(hr))
    {
        CATID catid = CATID_DeskBand;
        hr = pcr->RegisterClassImplCategories(CLSID_OVDeskBand, 1, &catid);
        pcr->Release(); 
    }

    CoUninitialize();

    return hr;
}
Exemplo n.º 16
0
// HRESULT UnRegisterCLSIDInCategory -  Remove entries from the registry
HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
{
	ICatRegister *pcr = NULL ; 
	HRESULT hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,   
		NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);  

	if (SUCCEEDED(hr))
	{
		// Unregister this category as being "implemented" by the class.
		CATID rgcatid[1];
		rgcatid[0] = catid;
		hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
	}

	if (pcr != NULL)
	{
		pcr->Release();
	}

	return hr;
} //lint !e1746  MFC自动生成的的函数
Exemplo n.º 17
0
//
// DllRegisterServer
//
// Register the COM objects (the tracker and the property page).
// Also add the tracker to the "Video Trackers" component category.
STDAPI DllRegisterServer()
{
    HRESULT hr = AMovieDllRegisterServer2( TRUE );
    if (FAILED(hr))
        return hr;

    ICatRegister *reg;
    hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_ALL, IID_ICatRegister, (void **)&reg);
    if (FAILED(hr))
        return hr;

    CATEGORYINFO catinfo;
    catinfo.catid = CATID_Trackers;
    catinfo.lcid = 0x409;
    wcscpy(catinfo.szDescription, L"Video Trackers");
    reg->RegisterCategories(1, &catinfo);
    reg->RegisterClassImplCategories(CLSID_CamShiftTracker, 1, const_cast<GUID *>(&CATID_Trackers));

    reg->Release();

    return NOERROR;
} // DllRegisterServer
Exemplo n.º 18
0
STDAPI DllRegisterServer(void)
{
	// registers object, typelib and all interfaces in typelib
	HRESULT hr = _Module.RegisterServer(TRUE);
	if (FAILED(hr)) return hr;

	ICatRegister   *pcr;

	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
		NULL, 
		CLSCTX_INPROC_SERVER, 
		IID_ICatRegister, 
		(LPVOID*)&pcr);
	
	if(SUCCEEDED(hr))
	{
		{
			CATEGORYINFO catinfo[1];

			catinfo[0].catid = CATID_LXFrameworkPlugin;
			catinfo[0].lcid = 0;
			wcscpy(catinfo[0].szDescription, L"LXFramework Plugin");
		
			pcr->RegisterCategories(sizeof(catinfo)/sizeof(CATEGORYINFO), catinfo);
		}

		{
			CATID rgcatid[1];

			rgcatid[0] = CATID_LXFrameworkPlugin;

			hr = pcr->RegisterClassImplCategories(CLSID_LXImageApp, 1, rgcatid);
		}

		pcr->Release();
	}

	return hr;
}
Exemplo n.º 19
0
//系统文件不修改
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)//lint !e715
{
	//USES_CONVERSION;

	ICatRegister* pcr = NULL;
	HRESULT hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
		NULL, 
		CLSCTX_INPROC_SERVER, 
		IID_ICatRegister, 
		(void**)&pcr);
	// Make sure the HKCR\Component Categories\{..catid...} key is registered.
	if (FAILED(hr))
	{
		return hr;
	}
	// Make sure the HKCR/Component Categories/{..catid}    
	// // key is registered.    
	CATEGORYINFO catinfo;
	catinfo.catid = catid;
	catinfo.lcid = 0x0409 ;     // english    

	// Make sure the provided description is not too long,
	// Only copy the first 127 characters if it is.
	int len = static_cast<int>(wcslen(catDescription)); 

	if (len > 127)
	{
		len = 127;
	}

	if(0 != wcsncpy_s(catinfo.szDescription, catDescription, (unsigned)len))
	{
		return S_FALSE;
	}
	catinfo.szDescription[len] = '\0';
	hr = pcr->RegisterCategories(1, &catinfo);
	pcr->Release();
	return hr;
}//lint !e1746 !e818
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription) {
	ICatRegister* pcr = NULL ;
    HRESULT hr = S_OK ;

	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
	if (FAILED(hr))
		return hr;

	CATEGORYINFO catinfo;
	catinfo.catid = catid;
	catinfo.lcid = 0x0409 ; // english

	int len = wcslen(catDescription);
	if (len>127)
		len = 127;
	wcsncpy_s(catinfo.szDescription, 127, catDescription, len);
	catinfo.szDescription[len] = '\0';

	hr = pcr->RegisterCategories(1, &catinfo);
	pcr->Release();

	return hr;
}
Exemplo n.º 21
0
HRESULT manageOPCDAcat(const GUID *service, int remove)
{
 HRESULT hr, hri;
 ICatRegister *pcr;

 hri = CoInitialize(0);
 hr = CoCreateInstance(
#ifndef __cplusplus
                       &
#endif
                       CLSID_StdComponentCategoriesMgr, 
                       NULL, CLSCTX_INPROC_SERVER, 
#ifndef __cplusplus
                       &
#endif
                       IID_ICatRegister, (void **)&pcr );

 if (FAILED(hr))
   {
    UL_INFO((LOGID, "%!l FAILED to get ICatRegister", hr));
   }
 else
   {
    CATID catid[2];

    if (0 == remove)
      {
       CATEGORYINFO catinf[2];
       catinf[0].catid = CATID_OPCDAServer10;
       wcscpy(catinf[0].szDescription, L"OPC Data Access Servers Version 1.0");
       catinf[0].lcid = 0x0409;
       catinf[1].catid = CATID_OPCDAServer20;
       wcscpy(catinf[1].szDescription, L"OPC Data Access Servers Version 2.0");
       catinf[1].lcid = 0x0409;

#ifdef __cplusplus
       hr = pcr->RegisterCategories(2, catinf);
#else
       hr = pcr->lpVtbl->RegisterCategories(pcr, 2, catinf);
#endif
       if (FAILED(hr))
         UL_INFO((LOGID, "%!l FAILED ICatRegister::RegisterCategories()", hr));
      }

    catid[0] = CATID_OPCDAServer10;
    catid[1] = CATID_OPCDAServer20;

#ifdef __cplusplus
    hr = remove? pcr->UnRegisterClassImplCategories(*service, 2, catid):
                 pcr->RegisterClassImplCategories(*service, 2, catid);
    pcr->Release();
#else
    hr = remove? pcr->lpVtbl->UnRegisterClassImplCategories(pcr, service, 2, catid):
                 pcr->lpVtbl->RegisterClassImplCategories(pcr, service, 2, catid);
    pcr->lpVtbl->Release(pcr);
#endif
    if (FAILED(hr))
      UL_INFO((LOGID, "%!l FAILED ICatRegister::%sRegisterClassImplCategories()",
              hr, remove? "Un": ""));
   }
 if (SUCCEEDED(hri)) CoUninitialize();
 UL_DEBUG((LOGID, "%!l ICatRegister::%sRegister", hr, remove? "Un": ""));
 return hr;
}
Exemplo n.º 22
0
STDAPI DllRegisterServer(void)
{
	USES_CONVERSION;

    // registers object, typelib and all interfaces in typelib
	HRESULT hr = _Module.RegisterServer(TRUE);
	if (FAILED(hr)) return hr;

	ICatRegister   *pcr;

	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
		NULL, 
		CLSCTX_INPROC_SERVER, 
		IID_ICatRegister, 
		(LPVOID*)&pcr);
	
	if(SUCCEEDED(hr))
	{
#if 0
		{
			CATEGORYINFO catinfo[1];

			catinfo[0].catid = CATID_LXMLPlugin;
			catinfo[0].lcid = 0;
			wcscpy(catinfo[0].szDescription, L"LXML Implementation");

			pcr->RegisterCategories(sizeof(catinfo)/sizeof(CATEGORYINFO), catinfo);
		}

		{
			CATID rgcatid[1];

			rgcatid[0] = CATID_LXMLPlugin;

			hr = pcr->RegisterClassImplCategories(CLSID_LXUIImplementation, 1, rgcatid);
		}
#endif

		pcr->Release();
	}

#if 0
	{
		LPOLESTR clsidString;
		StringFromCLSID(CLSID_ActiveXControl, &clsidString);

		{
			CRegKey key;
			key.Create(HKEY_CLASSES_ROOT, "lx3dfile\\CLSID");
			key.SetValue(W2A(clsidString));
		}

		{
			CRegKey key;
			key.Create(HKEY_CLASSES_ROOT, ".wrl");
			key.SetValue("lx3dfile");
			//key.SetValue("image/svg+xml", "Content Type");
		}
		{
			CRegKey key;
			key.Create(HKEY_CLASSES_ROOT, ".x3d");
			key.SetValue("lx3dfile");
			key.SetValue("model/x3d+xml", "Content Type");
		}
		{
			CRegKey key;
			key.Create(HKEY_CLASSES_ROOT, ".x3dv");
			key.SetValue("lx3dfile");
			//key.SetValue("image/svg+xml", "Content Type");
		}
		{
			CRegKey key;
			key.Create(HKEY_CLASSES_ROOT, ".3ds");
			key.SetValue("lx3dfile");
			//key.SetValue("image/svg+xml", "Content Type");
		}

		// Mime
		{
			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\model/x3d+xml");
				key.SetValue(".x3d", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\model/x3d-vrml");
				key.SetValue(".x3d", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\x-world/x-x3d");
				key.SetValue(".x3d", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\x-world/x-vrml");
				key.SetValue(".x3d", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\model/vrml");
				key.SetValue(".x3d", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\model/x3d");
				key.SetValue(".x3d", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}
		}
	}

	if (TRUE)
	{
		LPOLESTR clsidString = L"{5B90C952-8156-4ed2-9D76-BD9FDFC64436}";
		//StringFromCLSID(CLSID_LHTMLActiveDocument, &clsidString);


		_SetRegKey("LTesting.LTest.1", "LTest Class");
		_SetRegKey("LTesting.LTest.1\\CLSID", W2A(clsidString));
		_SetRegKey("LTesting.LTest.1\\Insertable", "0");
		if (TRUE)
		{
			_SetRegKey("LTesting.LTest.1\\DocObject", "0");
		}

		_SetRegKey("LTesting.LTest", "LTest Class");
		_SetRegKey("LTesting.LTest\\CLSID", W2A(clsidString));
		_SetRegKey("LTesting.LTest\\CurVer", "LTesting.LTest.1");

			//char* clsidString = "{06090DC5-EE21-4eca-B8AB-11FFA3F1A393}";

		_SetRegKey(CString("CLSID\\") + W2A(clsidString), "LTest Class");
		_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\ProgID", "LTesting.LTest.1");
		_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\VersionIndependentProgID", "LTesting.LTest");
		_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\Programmable", NULL);
		_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\InprocServer32", "C:\\WINNT\\System32\\LXUI.dll");
		_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\InprocServer32", "Apartment", "ThreadingModel");
		_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\Insertable", NULL);
		_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\Control", NULL);
		if (TRUE)
		{
			_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\DocObject", "0");
			_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\DefaultExtension", ".xht, LHTML Documents (*.xht)");
		}

		_SetRegKey(CString("CLSID\\") + W2A(clsidString) + "\\TypeLib", "{907526D5-5F3A-469D-B3F5-71FCF58B9E10}");

		if (TRUE)
		{
			TCHAR filename[MAX_PATH];
			{
				CRegKey key;
				key.Open(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE");

				DWORD dwCount = sizeof(filename);
				key.QueryValue(filename, NULL, &dwCount);
			}

	//	MessageBox(NULL, "7", "", MB_OK);

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "svgfile\\CLSID");
				key.SetValue(W2A(clsidString));
			}

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "svgfile\\DefaultIcon");
				key.SetValue("%SystemRoot%\\system32\\url.dll,0");
			}

	//	MessageBox(NULL, "8", "", MB_OK);

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "svgfile\\shell\\open\\command");

				TCHAR value[512];
				sprintf(value, "%s -nohome %%1", filename);
				key.SetValue(value);
			}

			// File extension associations
			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, ".svg");
				key.SetValue("svgfile");
				key.SetValue("image/svg+xml", "Content Type");
			}

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, ".svgz");
				key.SetValue("svgfile");
				key.SetValue("image/svg+xml", "Content Type");
			}

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, ".xht");
				key.SetValue("svgfile");
				key.SetValue("application/xhtml+xml", "Content Type");
			}

		// Mime associations
			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\image/svg+xml");
				key.SetValue(".svg", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}

			/*
			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\image/svg+xml");
				key.SetValue(".svgz", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}
			*/

			{
				CRegKey key;
				key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\application/xhtml+xml");
				key.SetValue(".xht", "Extension");
				key.SetValue(W2A(clsidString), "CLSID");
			}

		///////////
			CoTaskMemFree(clsidString);

			SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
		}
	}
#endif

	return hr;
}
Exemplo n.º 23
0
HRESULT OPCEngine::unregisterServer(void)
{ 
	_TRACE(TL_INF, TG_ENG, (_T("unregister server")));
	HRESULT res;

	{
		ICatRegister *cr;
		ICatInformation *ci = NULL ;
		IEnumCLSID* enumCLSID = NULL ;
		CATID catIDs[2];
		CLSID clsid ;

		if (SUCCEEDED(res = ::CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
			NULL, CLSCTX_ALL, IID_ICatRegister, (void **)&cr)))
		{
			// unregister server in categories
			catIDs[0] = CATID_OPCDAServer10;
			catIDs[1] = CATID_OPCDAServer20;
			res = cr->UnRegisterClassImplCategories(g_clsid, 2, catIDs);
			_TRACE(TL_INF, TG_ENG, (_T("unregister component implementations [0x%X]"), res));

			// check if this server was the last in the category
			if (SUCCEEDED(res = cr->QueryInterface(IID_ICatInformation, (void**)&ci)))
			{
				// OPC DA Server V1.0A
				if (SUCCEEDED (res = ci->EnumClassesOfCategories(1, &catIDs[0], 0, NULL, &enumCLSID)))
				{
					res = enumCLSID->Next(1, &clsid, NULL) ;

					// if result is S_FALSE, there no components are in this category, so remove it.
					if (res == S_FALSE)
					{
						// unregister the component category
						res = cr->UnRegisterCategories(1, &catIDs[0]) ;
						_TRACE(TL_INF, TG_ENG, (_T("unregister DA V1.0A component category [0x%X]"), res));
					}
					enumCLSID->Release();
				}

				// OPC DA Server V2.0
				if (SUCCEEDED (res = ci->EnumClassesOfCategories(1, &catIDs[1], 0, NULL, &enumCLSID)))
				{
					res = enumCLSID->Next(1, &clsid, NULL) ;

					// if result is S_FALSE, there no components are in this category, so remove it.
					if (res == S_FALSE)
					{
						// unregister the component category
						res = cr->UnRegisterCategories(1, &catIDs[1]) ;
						_TRACE(TL_INF, TG_ENG, (_T("unregister DA V2.0 component category [0x%X]"), res));
					}
					enumCLSID->Release();
				}

				ci->Release();
			}
			cr->Release();
		}

		CRegKey key, keyCLSID;
		DWORD ret;

		if (ret = keyCLSID.Open(HKEY_CLASSES_ROOT, _T("CLSID")) == ERROR_SUCCESS)
		{
			USES_CONVERSION;
			LPOLESTR wszClsid;
			LPTSTR clsid;
			StringFromCLSID(g_clsid, &wszClsid);
			clsid = W2T(wszClsid);
			CoTaskMemFree(wszClsid);

			if (ret = key.Open(keyCLSID, clsid) == ERROR_SUCCESS)
			{
				key.RecurseDeleteKey(_T("Implemented Categories"));
				key.Close();
			}
			else
				res = HRESULT_FROM_WIN32(ret);

			keyCLSID.Close();
		}
		else
			res = HRESULT_FROM_WIN32(ret);
	}

	// unregister COM Server object
	res = _Module.UnregisterServer();

	return res; 
} // unregisterServer