AfxDynamicDownCast fails ? |
Post Reply |
Author | |
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
Posted: 15 April 2009 at 12:44am |
Hi,
pObject = (CObject*)AfxDynamicDownCast(pObjectRuntime, pClass->CreateObject()); returns NULL in BOOL CXTPPropExchange::ExchangeObjectInstance(CObject*& pObject, CRuntimeClass* pObjectRuntime) when CXTPPropExchangeXMLNode's LoadFromFile() call using an xml file. I dont think this is the problem of XT but Is there any general cause for this problem like wrong visual c++ project settings etc ? Thanks in advance |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
Did you add DECLARE_SERIAL/IMLEMENT_SERIAL for your class ?
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hi,
I didnt have any new/derived classes This is the first command bar in the xml file that fail to downcast ... I hope this helps you <CommandBar Class="CXTPMenuBar" Type="0" BarID="1" Flags="95" Style="4194304" Title="Menu Bar" MRUWidth="32767" Closeable="0" ResourceId="16"> <Controls OriginalControls="1"> <Control Class="CXTPControlPopup" Type="2" Caption="&File" CommandBarId="16777216"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Edit" CommandBarId="16777217"/> <Control Class="CXTPControlPopup" Type="2" Caption="&View" CommandBarId="16777218"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Insert" CommandBarId="16777222"/> <Control Class="CXTPControlPopup" Type="2" Caption="F&ormat" CommandBarId="16777225"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Tools" CommandBarId="16777227"/> <Control Class="CXTPControlPopup" Type="2" Caption="T&able" CommandBarId="16777233"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Window" CommandBarId="16777238"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Help" CommandBarId="16777239"/> <OriginalControls> <Control Class="CXTPControlPopup" Type="2" Caption="&File" CommandBarId="16777241"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Edit" CommandBarId="16777242"/> <Control Class="CXTPControlPopup" Type="2" Caption="&View" CommandBarId="16777243"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Insert" CommandBarId="16777247"/> <Control Class="CXTPControlPopup" Type="2" Caption="F&ormat" CommandBarId="16777250"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Tools" CommandBarId="16777252"/> <Control Class="CXTPControlPopup" Type="2" Caption="T&able" CommandBarId="16777258"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Window" CommandBarId="16777263"/> <Control Class="CXTPControlPopup" Type="2" Caption="&Help" CommandBarId="16777264"/> </OriginalControls> </Controls> </CommandBar> |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hi, I just added some more data from the xml file that may help you ...
<?xml version="1.0" encoding="UTF-8"?> <Settings CompactMode="1"> <NormalLayout> <Options Schema="34" AlwaysShowFullMenus="0" ShowFullAfterDelay="1" ToolBarScreenTips="1" ToolBarAccelTips="0" LargeIcons="0" Animation="0"/> <CommandBars Schema="34"> <CommandBars> "The above menubar(CommandBar) goes here!" </CommandBars> <Layout> <DockState Version="34" ScreenSize="1400, 1050" Count="6"> <BarInfo0 BarId="1" MRUWidth="32767"/> <BarInfo1 BarId="123" MRUWidth="32767" PointPos="0, 26"/> <BarInfo2 BarId="140" MRUWidth="32767" PointPos="0, 52"/> <BarInfo3 BarId="279" Visible="0" MRUWidth="32767"/> <BarInfo4 BarId="160" MRUWidth="32767" MRUDockPosition="1"/> <BarInfo5 BarId="288" MRUWidth="32767" PointPos="0, 78"/> </DockState> <DockBars> <DockBar0 Count="11" Id1="1" Id3="123" Id5="140" Id7="279" Id9="288"/> <DockBar1 Count="3" Id1="160"/> </DockBars> </Layout> </CommandBars> <Shortcuts Schema="34"/> </NormalLayout> </Settings> |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
Strange then. Can you try GUI_VisualStudio sample - it also use XML to load state ?
Do you have standard exe application ? or some dll type ?
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Thanks Oleg,
I have standard exe. The loadcommandbars() didnt worked in my app before so i planned to change to xml based solution because i read somewhere in the forum that XT dont save in registry more than certain KB. Than i have tried VS_GUI and it worked fine so that i copied the code to save/load commandbar state from this sample to my app. But it didnt worked on my app. Now my total size of the cofiguration xml file size is 53.3 KB. Is that a problem ? I have enabled the customization by GetCommandBars()->EnableCustomization(TRUE) just before calling LoadFromFile() in OnCreate() of Mainframe Is that correct or am i missing something ? |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
These things can'tbe reason of such problem.
Afraid I need some sample that can reproduce problem to advice something. Try o make your app smaller and attach it.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
uploads/20090415_144233_CustomizeDlg.zip
Thanks Oleg, Just comment out the LoadCommandBars() and SaveCommandBars() in the CustomizeDlg sample and use the LoadFromFile() and SaveToFile() from VS_GUI sample and test out is the customization that we make loads correctly the next time we run the app. It didnt worked for me. |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
Don't think its same problem. You just don't have AfxOleInit() call that enables COM operations. Add it in InitInstance.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Thanks Oleg,
Yes after adding AfxOleInit() the customizedlg sample works correctly. But still i didnt find the way to reproduce the same problem in my app. |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hi,
In, BOOL CRuntimeClass::IsDerivedFrom(const CRuntimeClass* pBaseClass) const the line if (pClassThis == pBaseClass) returns FALSE When pClassThis is "CXTPCommandBar" and pBaseClass is "struct CRuntimeClass CXTPCommandBar::classCXTPCommandBar" Is that ring any bell ? |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hi,
Code to check BOOL CXTPPropExchange::ExchangeObjectInstance(CObject*& pObject, CRuntimeClass* pObjectRuntime) { if (!IsLoading()) { CRuntimeClass* pClass = pObject->GetRuntimeClass(); PX_RuntimeClass(this, _T("Class"), pClass, pObjectRuntime); } else { CRuntimeClass* pClass = NULL; PX_RuntimeClass(this, _T("Class"), pClass, pObjectRuntime); if (!pClass) return FALSE; const CRuntimeClass* pClassThis = pClass; while (pClassThis != NULL) { if (pClassThis == pObjectRuntime) return TRUE; #ifdef _AFXDLL pClassThis = (*pClassThis->m_pfnGetBaseClass)(); #else pClassThis = pClassThis->m_pBaseClass; #endif } return FALSE; // walked to the top, no match pObject = (CObject*)AfxDynamicDownCast(pObjectRuntime, pClass->CreateObject()); if (!pObject) return FALSE; } return TRUE; } |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
When i try using CustomizeDlg sample the pClass in
CRuntimeClass* CXTPPropExchange::FindRuntimeClass(LPCSTR szClassName) has value like "struct CRuntimeClass CXTPMenuBar::classCXTPMenuBar" but when i try using my app exe the value became like "CXTPMenuBar" ? |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi, see DECLARE_DYNAMIC sources. Myabe you override this macros ?
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Thanks Oleg, I checkedout my code it didnt have any overrides for DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC.
|
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
pClass get value like string only in the Red code region not in the Blue code region.
CRuntimeClass* CXTPPropExchange::FindRuntimeClass(LPCSTR szClassName) { CRuntimeClass* pClass; // search app specific classes AFX_MODULE_STATE* pModuleState = AfxGetModuleState(); for (pClass = pModuleState->m_classList; pClass != NULL; pClass = pClass->m_pNextClass) { if (lstrcmpA(szClassName, pClass->m_lpszClassName) == 0) { return pClass; } } #ifdef _AFXDLL // search classes in shared DLLs for (CDynLinkLibrary* pDLL = pModuleState->m_libraryList; pDLL != NULL; pDLL = pDLL->m_pNextDLL) { for (pClass = pDLL->m_classList; pClass != NULL; pClass = pClass->m_pNextClass) { if (lstrcmpA(szClassName, pClass->m_lpszClassName) == 0) { return pClass; } } } #endif ASSERT(FALSE); return 0; } |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Whoop! Finally find out the problem, My exe uses some dlls that still not ported to new XT version (which the exe uses) so the old XT dll come in the dynalib list and messed up the things.
Hearty Thanks Oleg for your patient and support. |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
kanitamildasan
Senior Member Joined: 01 February 2006 Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Time being i fixed it by the following code ...
#ifdef _AFXDLL CString version; version.Format("%d",_XTPLIB_VERSION_PREFIX); // search classes in shared DLLs for (CDynLinkLibrary* pDLL = pModuleState->m_libraryList; pDLL != NULL; pDLL = pDLL->m_pNextDLL) { char buff[MAX_PATH]; memset(buff,0,MAX_PATH); ::GetModuleFileName(pDLL->m_hModule,buff,MAX_PATH); if(CString(buff).Find(version) != -1) { for (pClass = pDLL->m_classList; pClass != NULL; pClass = pClass->m_pNextClass) { if (lstrcmpA(szClassName, pClass->m_lpszClassName) == 0) { return pClass; } } } } #endif |
|
Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2 Visual C++ 6.0 SP 6 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
ok :) great it works now.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |