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. C / C++ / MFC
  4. ATL - BSTRs and Properties

ATL - BSTRs and Properties

Scheduled Pinned Locked Moved C / C++ / MFC
c++beta-testingquestioncode-review
3 Posts 2 Posters 0 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.
  • R Offline
    R Offline
    RichB
    wrote on last edited by
    #1

    //////////////////////////////////////////////////////////// // All, // I would appreciate any feedback on this. // Is this the best way to do this? // Thanks, // Rich //////////////////////////////////////////////////////////// BSTR bstrProperty; STDMETHODIMP MyObject::get_Property(BSTR *pVal) { // According to KB article, I need // return a copy. *pVal = SysAllocString(bstrProperty); return S_OK; } STDMETHODIMP MyObject::put_Property(BSTR newVal) { // According to KB article, I need // my own copy to use and later free. bstrProperty = SysAllocString(newVal); return S_OK; }

    M 1 Reply Last reply
    0
    • R RichB

      //////////////////////////////////////////////////////////// // All, // I would appreciate any feedback on this. // Is this the best way to do this? // Thanks, // Rich //////////////////////////////////////////////////////////// BSTR bstrProperty; STDMETHODIMP MyObject::get_Property(BSTR *pVal) { // According to KB article, I need // return a copy. *pVal = SysAllocString(bstrProperty); return S_OK; } STDMETHODIMP MyObject::put_Property(BSTR newVal) { // According to KB article, I need // my own copy to use and later free. bstrProperty = SysAllocString(newVal); return S_OK; }

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      You also need to free the BSTRs before storing new values in them. So in get_Property: SysFreeString ( *pVal ); And in put_Property: SysFreeString ( bstrProperty ); I believe it's ok to pass NULL to SysFreeString(), but it wouldn't hurt to put in some standard pointer error-checking as well. --Mike-- http://home.inreach.com/mdunn/ This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use. :love: your :bob: with :vegemite: and :beer:

      R 1 Reply Last reply
      0
      • M Michael Dunn

        You also need to free the BSTRs before storing new values in them. So in get_Property: SysFreeString ( *pVal ); And in put_Property: SysFreeString ( bstrProperty ); I believe it's ok to pass NULL to SysFreeString(), but it wouldn't hurt to put in some standard pointer error-checking as well. --Mike-- http://home.inreach.com/mdunn/ This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use. :love: your :bob: with :vegemite: and :beer:

        R Offline
        R Offline
        RichB
        wrote on last edited by
        #3

        Mike, I appreciated your response. I'll look into your suggestions. Thanks, Rich

        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