Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 65413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:56:33+00:00 2026-05-10T18:56:33+00:00

OK, so I couldn’t really think of an apropos title that summarizes this. The

  • 0

OK, so I couldn’t really think of an apropos title that summarizes this.

The IPrintPipelinePropertyBag interface has the method AddProperty which aptly enough ‘adds a property to a property bag.’

http://msdn.microsoft.com/en-us/library/aa506384.aspx

AddProperty( [in, string] const wchar_t *pszName, [in] const VARIANT *pVar );

We use the following code to add a string to the property bag.

CComVariant varProperty = CComBSTR(someString); pPrintPropertyBag->AddProperty(L'SOME_PROPERTY', &varFilename); 

It’s pretty obvious, though, that the CComBSTR and CComVariant that is created goes out of scope after a while. I’m not sure if the PropertyBag handles the string and makes its own copy. Since we can store all kinds of stuff inside a VARIANT, this shouldn’t be the case.

Assuming the string isn’t handled, my question is, what is the pattern for doing this in COM? How should I pass a VARIANT that contains an allocated string, make that string available for other threads even if the thread that called AddProperty died first, and de-allocate the string properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:56:34+00:00Added an answer on May 10, 2026 at 6:56 pm

    When you call a COM function with strings or VARIANTs in most cases the only garantuee needed is that those objects are available throughout the call itself. After the call, the object itself is responsible for making copies of the data. For example VARIANT’s will most likely use the VariantCopy function that will copy strings, copy COM objects (increases reference count). The only thing you should worry about is when you pass an actual interface in the VARIANT: in that case the interface should be properly reference counted, and QueryInterface, AddRef, and Release should all be implemented accordingly. And don’t ever deallocate that object before the reference count reaches 0 😉

    EDIT: Oh, and if you want to learn more about COM programming, be sure to get ‘Essential COM’ by ‘Don Box’. Don Box is the COM guru, and that book will teach you almost anything you would ever want to know about COM and more 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 52k
  • Answers 52k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer A maven plugin is typically bound to execution in a… May 11, 2026 at 6:42 am
  • added an answer Try adding async: false to your options. $(ad_numbers).each(function() { ad_number… May 11, 2026 at 6:42 am
  • added an answer I'll add my 1 euro to the discussion but it's… May 11, 2026 at 6:42 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.