Solved

ATL/COM: IPersistPropertyBag::Load

Posted on 2001-08-24
10
733 Views
Last Modified: 2013-11-25
i have a composite control, which contains another control..
i have a property in this control which i want to forward to the other one..
as a simpler example:
i have a property TestProperty, which is of the contained object.. i made a TestProperty in the composite control and in put/get code i just do something like

STDMETHODIMP CNMGrid::put_TestProperty(VARIANT_BOOL newVal)
{
   if(m_containedCtrl)
        return m_containedCtrl->put_TestProperty(newVal);
   else
        return S_OK;
}

i implement IPersistPropertyBagImpl and, as a result, my put_ methods are called when launching from VB (as for example)..
but! the problem is that those are called _before_ the composite control instantiates the contained windows..
that means it gets in put_TestProperty before the contained control is created, so m_containedCtrl is NULL..

how can i solve this problem?

1. to reload the properties, but i don't know how to obtain the PropertyBag that i need..
2. other ideas? :)

for 1. i've tried something like the following code, but it doesn't work (i get pPropBag NULL).. i'm not doing the right thing?

CComPtr<IPersistPropertyBag> pPersistPropBag;
CComPtr<IPropertyBag> pPropBag;
CComPtr<IOleClientSite> pOleClientSite;
CComPtr<IOleContainer> pOleContainer;

HRESULT hr = GetClientSite(&pOleClientSite);

if (SUCCEEDED(hr))
{
     hr = pOleClientSite->GetContainer(&pOleContainer);

     if (SUCCEEDED(hr))
     {
          pOleContainer->QueryInterface(IID_IPropertyBag, (LPVOID*)&pPropBag);

          if (SUCCEEDED(hr))
          {
               this->QueryInterface(IID_IPersistPropertyBag, (LPVOID*)&pPersistPropBag);
               pPersistPropBag->Load(pPropBag, NULL);
          }
     }
}

i hope i was clear.. even if to be so is something unusual at me..
0
Comment
Question by:lame_programmer
10 Comments
 

Author Comment

by:lame_programmer
ID: 6421653
i desperately need a solution :\
0
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 300 total points
ID: 6423738
could you just store your property as a member of your class eg VARIANT_BOOL and then when you create your contained control use it to set the property of that control

eg

STDMETHODIMP CNMGrid::put_TestProperty(VARIANT_BOOL newVal)
{
  if(m_containedCtrl)
       return m_containedCtrl->put_TestProperty(newVal);
  else
  { // store it away
     m_varboolContained = newVal;
  }

  return S_OK;
}
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6424123
Listening..
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6424675
I guess you can't create the contained control earlier? ;)
Go with ShaunWilde's suggestion. Retriving the "original" Storage is impossible to do universally and safely.

0
 

Author Comment

by:lame_programmer
ID: 6427705
sorry for being late.. weekend...
i would go for what ShaunWilde said, i thought about it too, but i gaved a simple example - for what "i have for real" it's not very handful.. in fact i have 182 properties which i'll have to store :)
anyway.. if there won't be any answers i'll credit this one (since it solves my problem), even is not what i really wanted..
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:lame_programmer
ID: 6427711
"I guess you can't create the contained control earlier?"

this would fit my needs.. i can create an object earlier, but how i attach it to the hwnd of the one created?
0
 

Author Comment

by:lame_programmer
ID: 6427873
i've solved my problem in the following way (i'll describe samples of code):

- i have now a static label in the composite control
- i have an object of my type in the control
class ATL_NO_VTABLE CNMGrid :
     [..snip..]
     CComPtr<IMyContainedControl> m_pContained;

- i create an object of my type in the constructor of the composite control

CNMGrid::CNMGrid()
{
     [..snip..]
     
     m_pContained.CoCreateInstance(__uuidof(IMyContainedControl), NULL, CLSCTX_ALL);
}

- when the composite control receives WM_INITDIALOG i attach my object to the static's hwnd

LRESULT CNMGrid::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
     AtlAxAttachControl((IUnknown*)(m_pContained.p), GetDlgItem(IDC_STATIC), NULL);

     return 0;
}

maybe it helps - somewhere in future - anyone else who's having the same problem..
now, the points.. since the only solution i have is ShaunWilde i guess i'll accept that as an answer.. i should credit also peterchen, but i can't make everyone happy :\
0
 

Author Comment

by:lame_programmer
ID: 6427880
i haven't used it, because is something else than i wanted.. but it is a solution in almost all the cases :)
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6430091
thanks - but I feel unworthy - but thanks again
0
 

Author Comment

by:lame_programmer
ID: 6435808
any help worths something.. more than just 300 virtual points :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Cannot debug web form sthrough Visual Studio 2013 2 54
C++ Language error 28 149
FMX enumerated colours 2 72
Trouble with References... 5 25
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now