Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - AfxDynamicDownCast fails ?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

AfxDynamicDownCast fails ?

 Post Reply Post Reply
Author
Message
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Topic: AfxDynamicDownCast fails ?
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 15 April 2009 at 1:46am
Hi,
 
Did you add DECLARE_SERIAL/IMLEMENT_SERIAL for your class ?
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 15 April 2009 at 2:09am
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="&amp;File" CommandBarId="16777216"/>
        <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Edit" CommandBarId="16777217"/>
        <Control Class="CXTPControlPopup" Type="2" Caption="&amp;View" CommandBarId="16777218"/>
        <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Insert" CommandBarId="16777222"/>
        <Control Class="CXTPControlPopup" Type="2" Caption="F&amp;ormat" CommandBarId="16777225"/>
        <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Tools" CommandBarId="16777227"/>
        <Control Class="CXTPControlPopup" Type="2" Caption="T&amp;able" CommandBarId="16777233"/>
        <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Window" CommandBarId="16777238"/>
        <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Help" CommandBarId="16777239"/>                       
        <OriginalControls>
            <Control Class="CXTPControlPopup" Type="2" Caption="&amp;File" CommandBarId="16777241"/>
            <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Edit" CommandBarId="16777242"/>
            <Control Class="CXTPControlPopup" Type="2" Caption="&amp;View" CommandBarId="16777243"/>
            <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Insert" CommandBarId="16777247"/>
            <Control Class="CXTPControlPopup" Type="2" Caption="F&amp;ormat" CommandBarId="16777250"/>
            <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Tools" CommandBarId="16777252"/>
            <Control Class="CXTPControlPopup" Type="2" Caption="T&amp;able" CommandBarId="16777258"/>
            <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Window" CommandBarId="16777263"/>
            <Control Class="CXTPControlPopup" Type="2" Caption="&amp;Help" CommandBarId="16777264"/>                           
        </OriginalControls>
    </Controls>
</CommandBar>



Xtreme ToolkitPro 12.1.1
Win XP (32bit) - SP2
Visual C++ 6.0 SP 6
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 15 April 2009 at 3:50am
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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 15 April 2009 at 4:25am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 15 April 2009 at 5:02am
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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 15 April 2009 at 8:15am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 15 April 2009 at 2:18pm
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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 1:32am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 2:15am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 2:38am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 3:00am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 3:18am
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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 4:18am

Hi,

see DECLARE_DYNAMIC sources. Myabe you override this macros ?
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 5:15am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 5:22am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 6:21am
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
Back to Top
kanitamildasan View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01 February 2006
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote kanitamildasan Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 7:28am
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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 17 April 2009 at 1:49am
ok :) great it works now.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.