Persist ActiveX Controls At Runtime

I was writing a piece of code to store and load user preferences and wanted to persist the properties of some ActiveX controls on my dialog. The following procedure seems to do the job rather nicely.

BOOL PersistActiveX(CArchive& ar, CWnd* pActiveX)
{
 ASSERT(pActiveX);

 HRESULT hr = E_FAIL;

 // Create an archive stream
 CArchiveStream stm(&ar);
 LPPERSISTSTREAMINIT pPersStm = NULL;
 LPUNKNOWN lpUnk = pActiveX->GetControlUnknown();

 if(lpUnk)
 {
  // We have the IUnknown interface, so 
  // get the IPersistStreamInit
  lpUnk->QueryInterface(IID_IPersistStreamInit, 
                        (LPVOID*)&pPersStm);

  if(pPersStm)
  {
   // We have the relevant interface so load or save the data
   // based on the type of archive we have.
   if(ar.IsLoading())
   {
    hr = pPersStm->Load(&stm);
   }
   else
   {
    hr = pPersStm->Save(&stm, FALSE);
   }
  }

  // Must release the interface
  pPersStm->Release();
 }

 return SUCCEEDED(hr);
}
This can then be called simply by doing the following:
PersistActiveX(ar, GetDlgItem(IDC_SOMEACTIVEX));


Comments

  • Persistence CArray in ActiveX

    Posted by Legacy on 01/18/2004 12:00am

    Originally posted by: Diego

    Do you know how can I save a CArray in to the persistance of the ActiveX - PX_Blob????

    Thanks

    • hello

      Posted by tqqttq on 05/30/2005 03:06am

      good

      Reply
    Reply
  • Problem with successive serializing...

    Posted by Legacy on 09/14/2001 12:00am

    Originally posted by: Lez

    Hello,

    I'm using this function for serializing (loading) MFC ActiveX components. It Works great with the first component but i dont know why all others doesn't. It seems that the File (or the archive) is closing by the line pStream->Load(&stm).
    Does anyone have a solution ?

    Reply
  • How to use Web Browser control in ATL?

    Posted by Legacy on 10/09/2000 12:00am

    Originally posted by: Peng Fei

    Hi,

    I need use Web Browser control in my ATL,
    but I cannot create the dialog with Web Browser.

    Please give me a solution.

    regards

    Reply
  • Persist ActiveX Controls at Runtime

    Posted by Legacy on 02/28/2000 12:00am

    Originally posted by: kiran

    It is not mentioned as to how the CArchive object is created.

    Reply
  • CArchiveStream

    Posted by Legacy on 02/21/2000 12:00am

    Originally posted by: Erling Eybye

    CArchiveStream ??? is this class a MFC class ?
    I can't find it on Microsoft's homepage.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds