Print Page | Close Window

Use SetTheme in DLL

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=2736
Printed Date: 08 November 2025 at 9:17pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Use SetTheme in DLL
Posted By: Robby
Subject: Use SetTheme in DLL
Date Posted: 17 August 2005 at 9:32am

 my program will show a regular dialog, it's a normal cdialog,and it has a cbotton control, press this button will show another cdialog,this dialog is defined in my dll.

 in this dialog,I add a cxtbotton to it, and  then m_button.SetTheme(new CXTButtonThemeOfficeXP(TRUE)).

 it's ok when i show this dialog,the theme looks nice,but when i quit the program , an error occured,i'm sorry i can't remember the detail infomation about this error. this error occured both in dynamic link with mfc dll and static link with mfc. i test in a normal dialog program(normal means i build an .exe program not .dll),it works well.

i  just wanta know is there anything i should do when i use settheme function in my dll?

any advice would be appreciated!

P.S: i  use XT pro and VC6




Replies:
Posted By: Robby
Date Posted: 17 August 2005 at 9:06pm

the error says

debug assertion failed

in xtthememanager.cpp

i debug the code found that

the error happened in

CXTThemeManager::~CXTThemeManager()
{
 POSITION pos = m_mapDefaultFactories.GetStartPosition();
 void* pThemeFactoryClass;
 CXTThemeManagerStyleFactory* pFactory = 0;
 while(pos)
 {
  m_mapDefaultFactories.GetNextAssoc(pos, pThemeFactoryClass, (void *&)pFactory);
  delete pFactory;
 }

 ASSERT(m_factoryList.m_pHead == 0); //here
 m_factoryList.RemoveAll();
}



Posted By: Oleg
Date Posted: 18 August 2005 at 4:15am

Thank you for details, we will try to reproduce it to find solution for you.

Any hints what is your dll is? (MFC extension, MFC dll, simple Win32 dll)



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Oleg
Date Posted: 18 August 2005 at 6:15am

http://forum.codejock.com/uploads/oleg/2005-08-18_061524_demo.zip - 2005-08-18_061524_demo.zip

Check sample. DOn't see any assert errors :(



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Robby
Date Posted: 18 August 2005 at 9:23am

thank you for your reply.

it's a mfc dll. just some dialog things,i have checked sample for several times.

may be i should check again.



Posted By: franji1
Date Posted: 22 August 2005 at 3:54pm

I had a similar problem with version 8.6, which has to do NOT with when the DLL that "new"ed the specific custom theme, but with WHERE the constructor/destructor code of the custom theme is located.  In my case, the custom theme code is IN A DLL - this is BAD, as I will describe below.

The "global theme manager" is a static? global? object that gets "free"ed when the .EXE shuts down (I can't remember the specific call, but basically the C++ startup/shutdown code calls the destructors of all "global/static" objects at shutdown).  Regardless, the .DLL that has the code for the custom theme is now UNLOADED when the global theme manager is destroyed.  What's the big deal?  The deal is that the destructor of a theme is VIRTUAL, hence when the code in the global theme manger that deletes this custom theme is CALLED, the DLL that this virtual function pointed to is now GONE!

The "correct" fix is to implement ALL custom themes in the main .EXE, but I wanted mine in a DLL for reasons that are only valid to me, cuz sometimes I like it that way  

My fix for shutting down with custom themes implemented in a DLL, though crude, works.  "Standard" themes do not have this problem because their code is still "in memory" (even though we use the XTP as a DLL?!?).  Anyway, all I do is call CXTPPaintManager::SetTheme(xtpThemeOfficeXP) first thing in the OnDestroy of my main CFrameWnd dervied window. This causes the current theme to be swapped out with one of the "predefined" themes at the last possible moment. The previous theme's destructor is called while its code is still loaded, hence no crash at shutdown!



Posted By: Robby
Date Posted: 25 August 2005 at 7:41am

that make sense!

but my problem haven't appear for several days ,i do nothing .

it's amazing....

anyway thank you for your explicit reply




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net