Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. How to Get property value if it returns BSTR

How to Get property value if it returns BSTR

Scheduled Pinned Locked Moved COM
tutorialdatabasecom
4 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Inam
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • I 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

      S Offline
      S Offline
      safee ullah
      wrote on last edited by
      #2

      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

      I 1 Reply Last reply
      0
      • S safee ullah

        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

        I Offline
        I Offline
        Inam
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • I Inam

          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

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          Try VARIANT *pVarRes = new VARIANT(); V_VT(pVarRes) = VT_BSTR; and see if that helps.... Steve S

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups