Exemplo n.º 1
0
static void test_ProgIDFromCLSID(void)
{
    LPWSTR progid;
    HRESULT hr = ProgIDFromCLSID(&CLSID_CDeviceMoniker, &progid);
    ok(hr == S_OK, "ProgIDFromCLSID failed with error 0x%08lx\n", hr);
    if (hr == S_OK)
    {
        ok(!lstrcmpiW(progid, devicedotone), "Didn't get expected prog ID\n");
        CoTaskMemFree(progid);
    }

    progid = (LPWSTR)0xdeadbeef;
    hr = ProgIDFromCLSID(&CLSID_non_existent, &progid);
    ok(hr == REGDB_E_CLASSNOTREG, "ProgIDFromCLSID returned %08lx\n", hr);
    ok(progid == NULL, "ProgIDFromCLSID returns with progid %p\n", progid);
}
Exemplo n.º 2
0
//
// CLSIDToString
// Mostly for debugging purposes (TRACE et al)
//
HRESULT CLSIDToString(REFCLSID rclsid, LPTSTR ptzBuffer, size_t cchBuffer)
{
    ASSERT(NULL != ptzBuffer); ASSERT(0 != cchBuffer);

    LPOLESTR pOleString = NULL;

    HRESULT hr = ProgIDFromCLSID(rclsid, &pOleString);

    if (FAILED(hr))
    {
        hr = StringFromCLSID(rclsid, &pOleString);
    }

    if (SUCCEEDED(hr) && pOleString)
    {
#if defined(UNICODE)
        hr = StringCchCopy(ptzBuffer, cchBuffer, pOleString);
#else // UNICODE
        int nReturn = WideCharToMultiByte(CP_ACP, 0, pOleString,
            (int)wcslen(pOleString), ptzBuffer, (int)cchBuffer, NULL, NULL);

        if (nReturn == 0)
        {
            hr = HrGetLastError();
        }
#endif
    }

    CoTaskMemFree(pOleString);

    return hr;
}
Exemplo n.º 3
0
STDMETHODIMP CProviderInfo::get_Provider (enum ProviderRole Type,BSTR * pProgID )
{
	if(!pProgID) return E_POINTER;
	if(*pProgID) SysFreeString(*pProgID);
	HRESULT hr = S_OK;
	CLSID clType= GUID_NULL;

	switch(Type)
	{
	case enBatchPriceInfo:
		{
			clType = __uuidof( DataFeedBatchPriceInfo );
			break;
		}
	case enStructureProviderEx:
		{
			clType = __uuidof( DataFeedStructureInfo);
			break;
		}
	}

	BSTR bsData; 
	hr = ProgIDFromCLSID(clType, &bsData);

	if(SUCCEEDED(hr))
		*pProgID = SysAllocString((BSTR)bsData);
	else
		*pProgID = SysAllocString(L"");

	return hr;
}
Exemplo n.º 4
0
/**
 *\fn           std::string CLSIDToProgID(const char *clsid)
 *\brief        将CLSID转成类名,CLSID例:{2D7E0F8F-3215-11D0-BF28-0000E8D0D146}
 *\param[in]    const char * clsid 
 *\return       std::string 类名
 */
std::string CAddinProcess::CLSIDToProgID(const char *clsid)
{
    if (NULL == clsid) return "";

    USES_CONVERSION;
    CLSID clsid_data = {0};
    OLECHAR clsid_wstr[100] = {0};
    LPOLESTR prog_id = NULL;

    wcscpy(clsid_wstr, CT2OLE(clsid));

    HRESULT hr = CLSIDFromString(clsid_wstr, &clsid_data);

    if (FAILED(hr)) return "";

    hr = ProgIDFromCLSID(clsid_data, &prog_id);

    if (FAILED(hr)) return "";

    LPCTSTR lpstr =  OLE2CT(prog_id);

    std::string out(lpstr);

    IMalloc * pMalloc = NULL;

    hr = ::CoGetMalloc(1, &pMalloc);   // 取得 IMalloc

    if (SUCCEEDED(hr))
    {
        pMalloc->Free(prog_id);        // 释放ProgID内存
        pMalloc->Release();            // 释放IMalloc
    }

    return out;
}
HRESULT CTCPropBagOnRegKey::_SaveObject(const _bstr_t& strName,
  IUnknown* punkObj, BOOL bClearDirty, BOOL bSaveAllProperties)
{
  // Validate the specified parameters
  if (IsBadReadPtr(punkObj))
    return E_POINTER;

  // Create a subkey with the specified name
  CRegKey subkey;
  if (!strName.length())
    subkey = m_key;
  else
  {
    m_key.DeleteValue(strName);
    m_key.RecurseDeleteKey(strName);
    if (!subkey.Open(m_key, strName))
      return HRESULT_FROM_WIN32(GetLastError());
  }

  // QueryInterface for IPersistPropertyBag
  IPersistPropertyBagPtr pppb;
  HRESULT hr = punkObj->QueryInterface(__uuidof(pppb), (void**)&pppb);
  if (FAILED(hr))
    return hr;

  // Get the object's CLSID
  CLSID clsid;
  hr = pppb->GetClassID(&clsid);
  if (FAILED(hr))
    return hr;

  // Attempt first to convert the object's CLSID to a ProgID
  LPOLESTR pszProgID = NULL;
  if (SUCCEEDED(ProgIDFromCLSID(clsid, &pszProgID)))
  {
    subkey.WriteString(m_szProgID, pszProgID);
    CoTaskMemFree(pszProgID);
  }
  else
  {
    // Convert the object's CLSID to a string
    OLECHAR szClassID[64];
    StringFromGUID2(clsid, szClassID, sizeofArray(szClassID));
    subkey.WriteString(m_szCLSID, szClassID);
  }

  // Write the variant type value
  subkey.WriteDWord(m_szVariantType, DWORD(VarTypeFromUnknown(punkObj)));

  // Save the persistent properties of the object
  CComObjectStack<CTCPropBagOnRegKey> bag;
  bag.Init(subkey, strName, this);
  hr = pppb->Save(&bag, bClearDirty, bSaveAllProperties);

  // Return the last HRESULT
  return hr;
}
// IsCallbackRegistered()
// Determine if callback interface is already registered.
// Used by Register/Unregister menu item handlers.
BOOL CEventHandlerApp::IsCallbackRegistered() {
	LPOLESTR lpszProgID = NULL;
	HRESULT hr = ProgIDFromCLSID( CLSID_QBSDKCallback, &lpszProgID );
	if( lpszProgID ) {
		CoTaskMemFree( lpszProgID );
		lpszProgID = NULL;
	}

	return SUCCEEDED(hr);
}
Exemplo n.º 7
0
HRESULT CExeModule::UnregisterServer(BOOL bUnRegTypeLib, const CLSID* pCLSID)
{
	CComPtr<ICatRegister> spcr;
	HRESULT hr = spcr.CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC);
	if(SUCCEEDED(hr) && spcr!=NULL)
	{
			CATID catid = CATID_PriceProviders;
			CComBSTR bs;
			ProgIDFromCLSID(CLSID_ProviderInfo, &bs);
			spcr->UnRegisterClassImplCategories( CLSID_ProviderInfo, 1, &catid);
	}
	return CComModule::UnregisterServer(bUnRegTypeLib, pCLSID);
}
Exemplo n.º 8
0
STDMETHODIMP CProviderInfo::get_Provider(ProviderRole type, BSTR *pProgID)
{
	if(!pProgID) return E_POINTER;
	if(*pProgID) SysFreeString(*pProgID);
	HRESULT hr = S_OK;
	CLSID clType= GUID_NULL;

		switch(type)
		{
//		case enStructureProvider:
//			clType = CLSID_HyperFeedStructureProvider;
//			break;
		case enBatchPriceInfo:
			clType = __uuidof( ActivFeedBatchPriceInfo );
			break;
		case enStructureProviderEx:
			clType = __uuidof(ActivFeedStructureInfo);
			break;
//		case enPriceProvider: 
//			clType = CLSID_HyperFeedPriceProvider;
//			break;
//		case enPriceInfo:
//			clType = CLSID_HyperFeedPriceInfo;
//			break;
//		case enPriceInfoWithNotify:
//			clType = CLSID_HyperFeedPriceInfoWithNotify;
//			break;
//		case enBatchPriceInfo:
//			clType = CLSID_HyperFeedBatchPriceInfo;
//			break;
//		case enStructureProviderEx:
//			clType = CLSID_HyperFeedStructureProviderEx;
//			break;
		}

	BSTR bsData; 
	hr = ProgIDFromCLSID(clType, &bsData);

	if(SUCCEEDED(hr))
		*pProgID = SysAllocString((BSTR)bsData);
	else
		*pProgID = SysAllocString(L"");

	return hr;
}
Exemplo n.º 9
0
/******************************************************************************
 * ProgIDFromCLSID [COMPOBJ.62]
 *
 * Converts a class id into the respective Program ID. (By using a registry lookup)
 *
 * RETURNS
 *  S_OK on success
 *  riid associated with the progid
 */
HRESULT WINAPI ProgIDFromCLSID16(
  REFCLSID clsid, /* [in] class id as found in registry */
  LPOLESTR16 *lplpszProgID )/* [out] associated Program ID */
{
    LPOLESTR progid;
    HRESULT ret;

    ret = ProgIDFromCLSID( clsid, &progid );
    if (ret == S_OK)
    {
        INT len = WideCharToMultiByte( CP_ACP, 0, progid, -1, NULL, 0, NULL, NULL );
        ret = _xmalloc16(len, (SEGPTR*)lplpszProgID);
        if (ret == S_OK)
            WideCharToMultiByte( CP_ACP, 0, progid, -1, MapSL((SEGPTR)*lplpszProgID), len, NULL, NULL );
        CoTaskMemFree( progid );
    }
    return ret;
}
Exemplo n.º 10
0
static VALUE
ole_type_progid(ITypeInfo *pTypeInfo)
{
    HRESULT hr;
    TYPEATTR *pTypeAttr;
    OLECHAR *pbuf;
    VALUE progid = Qnil;
    hr = OLE_GET_TYPEATTR(pTypeInfo, &pTypeAttr);
    if (FAILED(hr))
        return progid;
    hr = ProgIDFromCLSID(&pTypeAttr->guid, &pbuf);
    if (SUCCEEDED(hr)) {
        progid = ole_wc2vstr(pbuf, FALSE);
        CoTaskMemFree(pbuf);
    }
    OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr);
    return progid;
}
Exemplo n.º 11
0
//=============================================================================
// 函数名称:	判断控件是否已安装
// 作者说明:	mushuai
// 修改时间:	2010-03-08
//=============================================================================
int IsOcxInstalled(const CString& id)
{
	int res=0;
	CLSID clsid;
	//check id is CLSID
	HRESULT hr = CLSIDFromString(CComBSTR(id),&clsid);
	if (SUCCEEDED(hr))
	{
		LPOLESTR progid=0;
		hr = ProgIDFromCLSID(clsid,&progid);
		if (SUCCEEDED(hr))
		{
			res=1;
		}
		else
		{
			if (hr == REGDB_E_CLASSNOTREG)
			{
				res=0;
			}
			else
			{
				res=-1;
			}
		}
	}
	else
	{
		hr =  CLSIDFromProgID(CComBSTR(id),&clsid);
		if (SUCCEEDED(hr))
		{
			res=1;
		}
		else if(hr ==REGDB_E_CLASSNOTREG || hr==CO_E_CLASSSTRING)
		{
			res = 0;
		}
		else 
		{
			res = -1;
		}
	}
	return res;
}
Exemplo n.º 12
0
HRESULT PASCAL CComObjectRoot::Error(const CLSID& clsid, LPCOLESTR lpszDesc,
	const IID& iid, HRESULT hRes)
{
	CComPtr<ICreateErrorInfo> pICEI;
	if (SUCCEEDED(CreateErrorInfo(&pICEI)))
	{
		CComPtr<IErrorInfo> pErrorInfo;
		pICEI->SetGUID(iid);
		LPOLESTR lpsz;
		ProgIDFromCLSID(clsid, &lpsz);
		if (lpsz != NULL)
			pICEI->SetSource(lpsz);
		CoTaskMemFree(lpsz);
		pICEI->SetDescription((LPOLESTR)lpszDesc);
		if (SUCCEEDED(pICEI->QueryInterface(IID_IErrorInfo, (void**)&pErrorInfo)))
			SetErrorInfo(0, pErrorInfo);
	}
	return (hRes == 0) ? DISP_E_EXCEPTION : hRes;
}
Exemplo n.º 13
0
HRESULT ComErrorInfo(const CLSID& clsid, REFIID riid, IErrorInfo ** ppErrInfo, LPCTSTR pszDesc)
{
    USES_CONVERSION;
    ICreateErrorInfo* pcei = NULL;
    IErrorInfo * pei = NULL;
    LPOLESTR lpsz;

    if(ppErrInfo == NULL) {
        return E_POINTER;
    }

    *ppErrInfo = NULL;

    if(clsid == CLSID_NULL) {
        return S_FALSE;
    }

    HRESULT hr = CreateErrorInfo(&pcei);
    if(FAILED(hr)) {
        return hr;
    }

    ProgIDFromCLSID(clsid, &lpsz);
    if (lpsz != NULL) {
        pcei->SetSource(lpsz);
        ::CoTaskMemFree(lpsz);
    }

    lpsz = T2OLE(pszDesc);
    pcei->SetDescription(lpsz);
    //Interface ID of the interface whose method is throwing the Except.
    pcei->SetGUID(riid);

    hr = pcei->QueryInterface(IID_IErrorInfo, (void**) &pei);
    if(SUCCEEDED(hr)) {
        *ppErrInfo = pei;
    }

    pcei->Release();
    return hr;
}
Exemplo n.º 14
0
	//*
	void local_host::get_clsid( const CATID& cat_id, LPCOLESTR server_name, CLSID& server_id )
	{
#if defined _DEBUG && defined _CONSOLE
		wprintf( L"get_clsid( %s )\n", server_name );
#endif

		CATID Implist[1] = { cat_id };
		ATL::CComPtr<IEnumCLSID> iEnum;
		HRESULT result = root_->EnumClassesOfCategories(1, Implist,0, NULL, &iEnum);
		if (FAILED(result))
		{
			throw opc_exception( result, OLESTR("Failed to get enum for categeories") );
		}

		GUID glist;
		ULONG actual;
		while((result = iEnum->Next(1, &glist, &actual)) == S_OK)
		{
			cotask_holder<OLECHAR> progID;

			HRESULT res = ProgIDFromCLSID(glist, progID.addr());			
			if(FAILED(res))
			{
				throw opc_exception( res, OLESTR("Failed to get ProgId from ClassId") );
			}
			else 
			{
#if defined _DEBUG && defined _CONSOLE
				wprintf( L"progId = %s\n", progID );
#endif
				if ( lstrcmpW( progID.get(), server_name ) == 0 )
				{
					server_id = glist;

					return;					
				}																
			}
		}
	}
Exemplo n.º 15
0
STDMETHODIMP CProviderInfo::get_Provider(ProviderRole type, BSTR *pProgID)
{
	if(!pProgID) return E_POINTER;
	HRESULT hr =S_OK;

	CLSID clType= GUID_NULL;

	switch(type)
	{
	case enStructureProvider:
		clType = CLSID_ATFStructureProvider;
		break;
	case enStructureInfo:
		clType = CLSID_ATFStructureInfo;
		break;
	case enPriceProvider: 
		clType = CLSID_ATFPriceProvider;
		break;
	case enPriceInfo:
		clType = CLSID_ATFPriceInfo;
		break;
	case enPriceInfoWithNotify:
		clType = CLSID_ATFPriceInfoWithNotify;
		break;
	}
	BSTR bsData; 
	hr = ProgIDFromCLSID(clType, &bsData);

	if(SUCCEEDED(hr))
		*pProgID = ::SysAllocString(bsData);
	else
		*pProgID = ::SysAllocString(L"");

	return hr;

}
Exemplo n.º 16
0
HRESULT primProgIDFromCLSID( const CLSID* clsid, WCHAR** clsidStr )
{
   if (!clsid)   clsid = &IID_NULL;
   if (clsidStr) return ProgIDFromCLSID( clsid, clsidStr );
            else return E_POINTER;
}
/// \param[in] configSection @copydoc initArg1
/// \param[in] configFile @copydoc initArg2
/// \param[in] host @copydoc initArg3
/// \param[in] options @copydoc initArg4
/// \param[in] progid @copydoc initArg5
/// \param[in] username @copydoc initArg6
/// \param[in] password @copydoc initArg7
lvDCOMInterface::lvDCOMInterface(const char *configSection, const char* configFile, const char* host, int options, const char* progid, const char* username, const char* password) : 
m_configSection(configSection), m_pidentity(NULL), m_pxmldom(NULL), m_options(options), 
	m_progid(progid != NULL? progid : ""), m_username(username != NULL? username : ""), m_password(password != NULL ? password : ""),
	m_mac_env(NULL)
	
{
	epicsThreadOnce(&onceId, initCOM, NULL);
	if (host != NULL && host[0] != '\0') 
	{
		m_host = host;
	}
	else
	{
		//		char name_buffer[MAX_COMPUTERNAME_LENGTH + 1];
		//		DWORD name_size = MAX_COMPUTERNAME_LENGTH + 1;
		//		if ( GetComputerNameEx(ComputerNameNetBIOS, name_buffer, &name_size) != 0 )
		//		{
		//			m_host = name_buffer;
		//		}
		//		else
		//		{
		//			m_host = "localhost";
		//		}			
		m_host = "localhost";
	}
	if (macCreateHandle(&m_mac_env, NULL) != 0)
	{
		throw std::runtime_error("Cannot create mac handle");
	}
	// load current environment into m_mac_env, this is so we can create a macEnvExpand() equivalent 
	// but tied to the environment at a specific time. It is useful if we want to load the same 
	// XML file twice but with a macro defined differently in each case 
	for(char** cp = environ; *cp != NULL; ++cp)
	{
		char* str_tmp = strdup(*cp);
		char* equals_loc = strchr(str_tmp, '='); // split   name=value   string
		if (equals_loc != NULL)
		{
		    *equals_loc = '\0';
		    macPutValue(m_mac_env, str_tmp, equals_loc + 1);
		}
		free(str_tmp);
	}
	//	m_doc = new TiXmlDocument;
	//	if ( !m_doc->LoadFile(configFile) )
	//	{
	//		delete m_doc;
	//		m_doc = NULL;
	//		throw std::runtime_error("Cannot load " + std::string(configFile) + ": load failure");
	//	}
	//	m_root = m_doc->RootElement();
	DomFromCOM();
	short sResult = FALSE;
	char* configFile_expanded = envExpand(configFile);
	m_configFile = configFile_expanded;
	HRESULT hr = m_pxmldom->load(_variant_t(configFile_expanded), &sResult);
	free(configFile_expanded);
	if(FAILED(hr))
	{
		throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure");
	}
	if (sResult != VARIANT_TRUE)
	{
		throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure");
	}
	std::cerr << "Loaded XML config file \"" << m_configFile << "\" (expanded from \"" << configFile << "\")" << std::endl;
	m_extint = doPath("/lvinput/extint/@path").c_str();
	epicsAtExit(epicsExitFunc, this);
	if (m_progid.size() > 0)
	{
		if ( CLSIDFromProgID(CT2W(m_progid.c_str()), &m_clsid) != S_OK )
		{
			throw std::runtime_error("Cannot find progId " + m_progid);
		}
	}
	else
	{
		m_clsid = LabVIEW::CLSID_Application;
		wchar_t* progid_str = NULL;
		if ( ProgIDFromCLSID(m_clsid, &progid_str) == S_OK )
		{
			m_progid = CW2CT(progid_str);
			CoTaskMemFree(progid_str);
		}
		else
		{
			m_progid = "LabVIEW.Application";
		}
	}
	wchar_t* clsid_str = NULL;
	if ( StringFromCLSID(m_clsid, &clsid_str) == S_OK )
	{
		std::cerr << "Using ProgID \"" << m_progid << "\" CLSID " << CW2CT(clsid_str) << std::endl;
		CoTaskMemFree(clsid_str);
	}
	else
	{
		std::cerr << "Using ProgID \"" << m_progid << "\" but StringFromCLSID() failed" << std::endl;
	}
}
Exemplo n.º 18
0
static HRESULT WINAPI datainit_GetInitializationString(IDataInitialize *iface, IUnknown *datasource,
                                boolean include_pass, LPWSTR *init_string)
{
    static const WCHAR provW[] = {'P','r','o','v','i','d','e','r','=',0};
    static const WCHAR colW[] = {';',0};
    datainit *This = impl_from_IDataInitialize(iface);
    DBPROPINFOSET *propinfoset;
    IDBProperties *props;
    DBPROPIDSET propidset;
    ULONG count, infocount;
    WCHAR *progid, *desc;
    DBPROPSET *propset;
    IPersist *persist;
    HRESULT hr;
    CLSID clsid;
    int i, len;

    TRACE("(%p)->(%p %d %p)\n", This, datasource, include_pass, init_string);

    /* IPersist support is mandatory for data sources */
    hr = IUnknown_QueryInterface(datasource, &IID_IPersist, (void**)&persist);
    if (FAILED(hr)) return hr;

    memset(&clsid, 0, sizeof(clsid));
    hr = IPersist_GetClassID(persist, &clsid);
    IPersist_Release(persist);
    if (FAILED(hr)) return hr;

    progid = NULL;
    ProgIDFromCLSID(&clsid, &progid);
    TRACE("clsid=%s, progid=%s\n", debugstr_guid(&clsid), debugstr_w(progid));

    /* now get initialization properties */
    hr = IUnknown_QueryInterface(datasource, &IID_IDBProperties, (void**)&props);
    if (FAILED(hr))
    {
        WARN("IDBProperties not supported\n");
        CoTaskMemFree(progid);
        return hr;
    }

    propidset.rgPropertyIDs = NULL;
    propidset.cPropertyIDs = 0;
    propidset.guidPropertySet = DBPROPSET_DBINIT;
    propset = NULL;
    count = 0;
    hr = IDBProperties_GetProperties(props, 1, &propidset, &count, &propset);
    if (FAILED(hr))
    {
        WARN("failed to get data source properties, 0x%08x\n", hr);
        CoTaskMemFree(progid);
        return hr;
    }

    infocount = 0;
    IDBProperties_GetPropertyInfo(props, 1, &propidset, &infocount, &propinfoset, &desc);
    IDBProperties_Release(props);

    /* check if we need to skip password */
    len = strlenW(progid) + strlenW(provW) + 1; /* including ';' */
    for (i = 0; i < count; i++)
    {
        WCHAR *descr = get_propinfo_descr(&propset->rgProperties[i], propinfoset);
        if (descr)
        {
            /* include '=' and ';' */
            len += strlenW(descr) + 2;
            len += get_propvalue_length(&propset->rgProperties[i]);
        }

        if ((propset->rgProperties[i].dwPropertyID == DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO) &&
            (V_BOOL(&propset->rgProperties[i].vValue) == VARIANT_FALSE))
           include_pass = FALSE;
    }

    len *= sizeof(WCHAR);
    *init_string = CoTaskMemAlloc(len);
    *init_string[0] = 0;

    /* provider name */
    strcatW(*init_string, provW);
    strcatW(*init_string, progid);
    strcatW(*init_string, colW);
    CoTaskMemFree(progid);

    for (i = 0; i < count; i++)
    {
        WCHAR *descr;

        if (!include_pass && propset->rgProperties[i].dwPropertyID == DBPROP_AUTH_PASSWORD) continue;

        descr = get_propinfo_descr(&propset->rgProperties[i], propinfoset);
        if (descr)
        {
            static const WCHAR eqW[] = {'=',0};
            strcatW(*init_string, descr);
            strcatW(*init_string, eqW);
            write_propvalue_str(*init_string, &propset->rgProperties[i]);
            strcatW(*init_string, colW);
        }
    }

    free_dbpropset(count, propset);
    free_dbpropinfoset(infocount, propinfoset);
    CoTaskMemFree(desc);

    if (!include_pass)
        TRACE("%s\n", debugstr_w(*init_string));
    return S_OK;
}
Exemplo n.º 19
0
// **************************************************************************
// DisplayComponentCatList ()
//
// Description:
//	Construct a list of installed 1.0 and 2.0 OPC servers and insert into 
//	tree control.
//
// Parameters:
//  HTREEITEM	hParent		Handle of parent tree control item.
//	CATID		catid		Catagory ID (CATID_OPCDAServer10 or
//							  CATID_OPCDAServer20).
//
// Returns:
//  void
// **************************************************************************
void CKServerGeneralPage::DisplayComponentCatList (HTREEITEM hParent, CATID catid)
{
	HRESULT hr;

	// Make sure COM is initialized:
	hr = CoInitializeEx (NULL, COINIT_MULTITHREADED);

	if (SUCCEEDED (hr))
	{
		ICatInformation *pCat = NULL;

		// Get component category manager:
		hr = CoCreateInstance (CLSID_StdComponentCategoriesMgr, 
			NULL,
			CLSCTX_SERVER, 
			IID_ICatInformation,
			(void **)&pCat);

		// If succeeded, enumerate registered components:
		if (SUCCEEDED (hr))
		{
			IEnumCLSID *pEnum = NULL;

			CATID arrcatid [1];
			arrcatid [0] = catid;

			// Enumerate registered components based on clsid:
			hr = pCat->EnumClassesOfCategories (
				sizeof (arrcatid) / sizeof (CATID),	// number of catids in the array that follows
				arrcatid,							// catid array
				0, 
				NULL,
				&pEnum);							// clsid enumerator for registered components under this category

			// If succeeded, process results:
			if (SUCCEEDED (hr))
			{
				GUID guid;
				ULONG fetched;

				// Loop over enumerated components.  Call enemerator's next
				// member function to reference next component and get its
				// guid:
				while ((hr = pEnum->Next (1, &guid, &fetched)) == S_OK)
				{
					// Get the ProgID from the guid:
					WCHAR *wszProgID;
					hr = ProgIDFromCLSID (guid, &wszProgID);

					// If succeeded, add component to list:
					if (SUCCEEDED (hr))
					{
						// ProgID string will be in UNICODE format.  Convert to 
						// ANSI format if this is and ANSI build.  Insert component
						// into list:
					#ifdef _UNICODE
						m_pServerList->InsertItem (wszProgID, ILI_COMPONENT, ILI_COMPONENT, hParent);
					#else
						TCHAR szProgID [DEFBUFFSIZE];

						_wcstombsz (szProgID, wszProgID, sizeof (szProgID) / sizeof (TCHAR));
						m_pServerList->InsertItem (szProgID, ILI_COMPONENT, ILI_COMPONENT, hParent);
					#endif
						// It is up to us to free the Prog ID string memory:
						CoTaskMemFree (wszProgID);
					}
				}

				// Release our enumerator:
				pEnum->Release ();
			}
			// release our category mamager
			pCat->Release ();
		}
		// Uninitialize COM:
		CoUninitialize ();
	}
}
Exemplo n.º 20
0
FARINTERNAL UtContentsStmTo10NativeStm
	(LPSTORAGE pstg, REFCLSID rclsid, BOOL fDeleteSrcStm, UINT FAR* puiStatus)
{
	CLIPFORMAT	cf;
	LPOLESTR	lpszUserType = NULL;
	HRESULT		error;
	LPSTREAM	pstmSrc = NULL;
	LPSTREAM	pstmDst = NULL;
			
	*puiStatus = NULL;
	
	if (error = ReadFmtUserTypeStg(pstg, &cf, &lpszUserType))
		return error;
		
	
	if (! ((cf == CF_DIB  && rclsid == CLSID_PBrush)
			|| (cf == CF_METAFILEPICT && rclsid == CLSID_MSDraw))) {
		error = ResultFromScode(DV_E_CLIPFORMAT);
		goto errRtn;
	}
			
	if (error = pstg->OpenStream(OLE_CONTENTS_STREAM, NULL,
						(STGM_READ|STGM_SHARE_EXCLUSIVE),
						0, &pstmSrc)) {
		*puiStatus |= CONVERT_NOSOURCE;	

		// check whether OLE10_NATIVE_STREAM exists
		if (pstg->OpenStream(OLE10_NATIVE_STREAM, NULL,
				(STGM_READ|STGM_SHARE_EXCLUSIVE), 0, &pstmDst))
			*puiStatus |= CONVERT_NODESTINATION;
		else {
			pstmDst->Release();
			pstmDst = NULL;
		}
		
		goto errRtn;
	}
	
	if (error = OpenOrCreateStream(pstg, OLE10_NATIVE_STREAM, &pstmDst)) {
		*puiStatus |= CONVERT_NODESTINATION;						
		goto errRtn;
	}
	
	if (cf == CF_METAFILEPICT)
		error = UtPlaceableMFStmToMSDrawNativeStm(pstmSrc, pstmDst);
	else
		error = UtDIBFileStmToPBrushNativeStm(pstmSrc, pstmDst);
	
errRtn:
	if (pstmDst)
		pstmDst->Release();
			
	if (pstmSrc)
		pstmSrc->Release();
	
	if (error == NOERROR) {
		LPOLESTR lpszProgId = NULL;
		ProgIDFromCLSID(rclsid, &lpszProgId);
		
		error = WriteFmtUserTypeStg(pstg,
						RegisterClipboardFormat(lpszProgId),
						lpszUserType);

		if (lpszProgId)
			delete lpszProgId;
	}
	
	if (error == NOERROR) {
		if (fDeleteSrcStm)				
			pstg->DestroyElement(OLE_CONTENTS_STREAM);
	} else {
		pstg->DestroyElement(OLE10_NATIVE_STREAM);	
	}	
	
	if (lpszUserType)
		delete lpszUserType;
	
	return error;
}