How to Get property value if it returns BSTR
-
I have a com object in which there are different properties. When i get these values through it works well when property is returning long or some other integer but it crashes when property is returning bstr. Take a look at my code and guide me that what i did wrong. VARIANT pvResult; memset(&pvResult, 0, sizeof pvResult); VariantInit(&pvResult); DISPID dispID=this->pColl->getMemberID(index); DISPPARAMS dispParamsNoArgs={NULL,NULL,0,0}; HRESULT hr=pDispatch->Invoke(dispID,IID_NULL,LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,&dispParamsNoArgs, &pvResult,NULL,&nArgErr); Thanx in advance Inam
-
I have a com object in which there are different properties. When i get these values through it works well when property is returning long or some other integer but it crashes when property is returning bstr. Take a look at my code and guide me that what i did wrong. VARIANT pvResult; memset(&pvResult, 0, sizeof pvResult); VariantInit(&pvResult); DISPID dispID=this->pColl->getMemberID(index); DISPPARAMS dispParamsNoArgs={NULL,NULL,0,0}; HRESULT hr=pDispatch->Invoke(dispID,IID_NULL,LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,&dispParamsNoArgs, &pvResult,NULL,&nArgErr); Thanx in advance Inam
u have forgotten the last line return pvResult.bstrval; (offcourse after making your method of the type returning bstr) and if u already have it there in your code..then take a look at the following code, also if it doenot work then try looking into the dispatch map..have u given the correct VTs there for the return type?? //******************************* //body of a method returning BSTR DISPPARAMS * DispParam1 = new DISPPARAMS(); EXCEPINFO excep; UINT nArgErr; VARIANT *pVarRes = new VARIANT(); DispParam1->cArgs = 0; //number of arguments DispParam1->cNamedArgs = 0;// Number of named arguments. DispParam1->rgdispidNamedArgs = NULL; // Dispatch IDs of named arguments. IF1BookImpl::Invoke(DISPID_F1_Text, IID_NULL , ::GetUserDefaultLCID(), DISPATCH_PROPERTYGET, DispParam1, pVarRes , &excep, &nArgErr); delete DispParam1; return pVarRes->bstrVal; //******************************* regards safee
-
u have forgotten the last line return pvResult.bstrval; (offcourse after making your method of the type returning bstr) and if u already have it there in your code..then take a look at the following code, also if it doenot work then try looking into the dispatch map..have u given the correct VTs there for the return type?? //******************************* //body of a method returning BSTR DISPPARAMS * DispParam1 = new DISPPARAMS(); EXCEPINFO excep; UINT nArgErr; VARIANT *pVarRes = new VARIANT(); DispParam1->cArgs = 0; //number of arguments DispParam1->cNamedArgs = 0;// Number of named arguments. DispParam1->rgdispidNamedArgs = NULL; // Dispatch IDs of named arguments. IF1BookImpl::Invoke(DISPID_F1_Text, IID_NULL , ::GetUserDefaultLCID(), DISPATCH_PROPERTYGET, DispParam1, pVarRes , &excep, &nArgErr); delete DispParam1; return pVarRes->bstrVal; //******************************* regards safee
-
Infact program crashes when it executes the function invoke and in pVarRes there is coming bstr through get property but if long or int is coming it works well. Now i am not understanding what to do Regards minamkhan Inam