Click here to Skip to main content
15,901,205 members
Home / Discussions / COM
   

COM

 
GeneralRe: What are the rules for changing a published COM interface? Pin
Christian Graus22-Feb-05 8:41
protectorChristian Graus22-Feb-05 8:41 
GeneralCOM with C# multi client model Pin
sokettepower20-Feb-05 23:50
sokettepower20-Feb-05 23:50 
GeneralRe: COM with C# multi client model Pin
vishalmore21-Feb-05 18:08
vishalmore21-Feb-05 18:08 
QuestionCan we set a global hook in a COM object? Pin
nadzzz20-Feb-05 7:24
nadzzz20-Feb-05 7:24 
AnswerRe: Can we set a global hook in a COM object? Pin
Jörgen Sigvardsson20-Feb-05 9:02
Jörgen Sigvardsson20-Feb-05 9:02 
AnswerRe: Can we set a global hook in a COM object? Pin
vishalmore20-Feb-05 18:23
vishalmore20-Feb-05 18:23 
GeneralError firing callback event Pin
Mayur Mahajan19-Feb-05 19:03
Mayur Mahajan19-Feb-05 19:03 
GeneralIPropertyBag Pin
nsrsetty18-Feb-05 18:33
nsrsetty18-Feb-05 18:33 
I have a problem. I need a COM dll, which takes a string as a filename and has to return a IPropertyBag by reading the file. The file may be simple text file, that consists a name value pairs. Once the file is read, the name value pair has to be added to the IPropertyBag. From the client I should be able to retrieve the name value information from the IPropertyBag.

The interface is defined like this
__interface IMetadataParser : IDispatch
{
[id(0), helpstring("method ParseMetadata")]
HRESULT ParseMetadata( [in] BSTR bstrXMLFilePath, [in,out] IPropertyBag** ppPropMetadataBag );
};

The client code looks like this.

hr = CoCreateInstance( CLSID_CMetadataParser, NULL, CLSCTX_INPROC_SERVER,
IID_IUnknown, (void**)&m_oMetadataParser );
CComObject<csubcomppropertybag> *pIOCRPropBag;
hr = CComObject<csubcomppropertybag>::CreateInstance(&pIOCRPropBag);
CComPtr<ipropertybag> pPropBg = NULL;
HRESULT hResStack = pIOCRPropBag->QueryInterface(IID_IPropertyBag, (void**)&pPropBg);
CComQIPtr<ipersistpropertybag> pISubPPB(m_oMetadataParser);
m_oMetadataParser->ParseMetadata(bstrXMLFilePath, &pPropBg1);

The definition of the class CSubCompPropertyBag is as follows:


typedef std::map<std::string, variant=""> PropBag;
typedef PropBag::iterator PropBag_IT;
typedef std::pair<std::string, variant=""> MapEntryPair;


CComModule _Module; //this should be in client

class ATL_NO_VTABLE CSubCompPropertyBag :
public CComObjectRootEx<ccomsinglethreadmodel>,
public IPropertyBag
{
public:

CSubCompPropertyBag()
{
ATLTRACE(_T("CSubCompPropertyBag is constructed \n"));
}

~CSubCompPropertyBag()
{

PropBag_IT bagIt = m_propBagMap.begin();
while(bagIt != m_propBagMap.end())
{
VARIANT varDel = bagIt->second;
if(VT_BSTR == varDel.vt)
::SysFreeString(varDel.bstrVal);
bagIt++;
}

m_propBagMap.erase(m_propBagMap.begin(), m_propBagMap.end());
ATLTRACE(_T("CSubCompPropertyBag is destructed \n"));
}

DECLARE_PROTECT_FINAL_CONSTRUCT()

DECLARE_NO_REGISTRY()

BEGIN_COM_MAP(CSubCompPropertyBag)
COM_INTERFACE_ENTRY(IPropertyBag)
END_COM_MAP()



//Method implement the IPropertyBag::Read() function
// move property value from private map to *pVar based on pVar->vt
//this function will be called from IPersistPropertyBag::Load() method
// for each property in ATL property map
STDMETHOD(Read)(LPCOLESTR pszPropName, VARIANT *pVar, IErrorLog *pErrorLog)
{
USES_CONVERSION;
if ((pVar == NULL) || (pszPropName == NULL))
return E_INVALIDARG;
std::string sPropName(W2A(pszPropName));
ATLTRACE("CFlowPropertyBag::Read() get called for property %s \n", sPropName.c_str() );
PropBag_IT bagIt = m_propBagMap.find(sPropName);
if (bagIt == m_propBagMap.end())
{
ATLTRACE("Fail to find the property %s in property bag\n", sPropName.c_str());
return E_FAIL;
}
else
{
try
{
VARIANT varValue = bagIt->second;

::VariantInit(pVar);
if(VT_ARRAY != varValue.vt)
{
HRESULT hr = ::VariantCopy(pVar,&varValue);
if(FAILED(hr))
throw E_FAIL;
}
else
{
SAFEARRAY *psaLanguage = varValue.parray;
pVar->vt = VT_ARRAY;
pVar->parray = psaLanguage;
}

ATLTRACE("Set property value from property bag completed\n");
return S_OK;
}
catch(...)
{
return E_FAIL;
}
}
}

//Method implement the IPropertyBag::Write() function
// move property value from *pVar to private map
//this function will be called from IPersistPropertyBag::Save() method
// for each property in ATL property map
STDMETHOD(Write)(LPCOLESTR pszPropName, VARIANT *pVar)
{
USES_CONVERSION;
if ((pVar == NULL) || (pszPropName == NULL))
return E_INVALIDARG;
std::string sPropName(W2A(pszPropName));
ATLTRACE("CFlowPropertyBag::Write() get called for property %s \n", sPropName.c_str() );
try
{
PropBag_IT bagIt = m_propBagMap.find(sPropName);
if (bagIt != m_propBagMap.end())
{
m_propBagMap.erase(bagIt);
}

VARIANT varVal;
::VariantInit(&varVal);

if(VT_ARRAY != pVar->vt)
{
HRESULT hr = ::VariantCopy( &varVal,pVar);
if(FAILED(hr))
throw E_FAIL;
}
else
{
SAFEARRAY *psaLanguage = pVar->parray;
varVal.vt = VT_ARRAY;
varVal.parray = psaLanguage;
}

std::pair<propbag_it, bool=""> ret =
m_propBagMap.insert(MapEntryPair(sPropName, varVal));
if (ret.second != TRUE)
throw E_FAIL;

ATLTRACE(_T("Write property into property bag completed\n"));
return S_OK;
}
catch(...)
{
return E_FAIL;
}
}
PropBag m_propBagMap;
};


Thanks in advance for the help.
GeneralCOM Service Pin
Vinicius Pontes18-Feb-05 0:04
Vinicius Pontes18-Feb-05 0:04 
GeneralRe: COM Service Pin
ThatsAlok19-Feb-05 6:04
ThatsAlok19-Feb-05 6:04 
GeneralRe: COM Service Pin
Vinicius Pontes20-Feb-05 23:38
Vinicius Pontes20-Feb-05 23:38 
GeneralRe: COM Service Pin
ThatsAlok21-Feb-05 0:38
ThatsAlok21-Feb-05 0:38 
GeneralCreate a new Thread Pin
BEamer17-Feb-05 2:25
BEamer17-Feb-05 2:25 
GeneralExcel COM Pin
MJWhiteman217-Feb-05 0:44
MJWhiteman217-Feb-05 0:44 
GeneralRe: Excel COM Pin
MJWhiteman217-Feb-05 3:27
MJWhiteman217-Feb-05 3:27 
GeneralInterprocess communication Pin
ravishanker16-Feb-05 17:17
ravishanker16-Feb-05 17:17 
GeneralMSComm32 dependances Pin
Trankil16-Feb-05 6:26
Trankil16-Feb-05 6:26 
GeneralRe: MSComm32 dependances Pin
rwestgraham16-Feb-05 16:43
rwestgraham16-Feb-05 16:43 
QuestionWho have the SkinCrafter dll ? Pin
rushing15-Feb-05 22:16
rushing15-Feb-05 22:16 
Generalrestore IXMLDOMElement from pointer Pin
Konrad Windszus15-Feb-05 1:18
Konrad Windszus15-Feb-05 1:18 
GeneralMS word Pin
merlinos14-Feb-05 14:43
merlinos14-Feb-05 14:43 
GeneralIDTExtensbility2 add-in deployment Pin
m6reid14-Feb-05 11:10
sussm6reid14-Feb-05 11:10 
GeneralRe: IDTExtensbility2 add-in deployment Pin
vishalmore21-Feb-05 18:52
vishalmore21-Feb-05 18:52 
GeneralMS Office docs Pin
Chna12-Feb-05 20:57
Chna12-Feb-05 20:57 
GeneralRe: MS Office docs Pin
vishalmore13-Feb-05 20:49
vishalmore13-Feb-05 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.