Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Problem with XtToolkit with MFC shared DLL
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Problem with XtToolkit with MFC shared DLL

 Post Reply Post Reply
Author
Message
jojoba View Drop Down
Newbie
Newbie


Joined: 17 August 2011
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote jojoba Quote  Post ReplyReply Direct Link To This Post Topic: Problem with XtToolkit with MFC shared DLL
    Posted: 17 August 2011 at 9:47am
Hi,

I'm new to both MFCs and XtToolkit. I was asked to migrate an MFC application (containing both native and managed code) in which XtToolkit is used towards a new WPF application. The idea is to slowly move the many functionalities from the Win32 MFC code to .net, while the application is still being used by several people.
We therefore try to host the current application (the MFC executable) in a newly-created WPF shell and before migrating the functionalities, we try to make sure that each one still works in the new application.

The MFC code is now compiled into a DLL and we load that DLL from the WPF shell. We had to play a bit with the code in order the ::InitInstance function of our derived class of CWinApp to be called (as described in http://support.microsoft.com/kb/148791) but the application is now properly created, hosted and displayed as before.

Unfortunately, we get asserts and crashes in XtToolkit whenever we click on a menu option : AfxGetApp and AfxGetResourceHandle both return NULL. Here's an example of the kind of assert we get :

CXTRegistryManager::CXTRegistryManager(HKEY hKeyBase/*=HKEY_CURRENT_USER*/)
{
    m_strINIFileName = xtAfxData.strINIFileName;

    m_pWinApp = AfxGetApp();
    ASSERT(m_pWinApp != NULL);
...

From what I understand, the crash occurs whenever an XT object (for example a CXTCoolMenu) traps a Windows message directly. In those cases, both AfxGetApp and AfxGetResourceHandle fail, while they return the proper pointers when called directly from our code. Indeed, I can set a breakpoint in that code and I won't get asserts or crashes when this code is executed during the initialization process (that originates from our code) but the same code will fail when the call originates from trapping a windows message.

Note that the resources are still properly set for XtToolkit : we still call xtAfxData.InitResources(...); properly, etc. Unless I missed something, we go through the same code path as before.

Do you have any clue as to what could possibly go wrong in those cases ? Did I miss something ? Do I try to do something illegal ?

Because of my company's firewall, I can't upload a file so I attached the callstacks at the end of this message.

Thanks for your help.

Jonathan
------

The code where the assert is located :

CXTRegistryManager::CXTRegistryManager(HKEY hKeyBase/*=HKEY_CURRENT_USER*/)
{
    m_strINIFileName = xtAfxData.strINIFileName;

    m_pWinApp = AfxGetApp();
    ASSERT(m_pWinApp != NULL);

    ASSERT(hKeyBase == HKEY_CURRENT_USER || hKeyBase == HKEY_LOCAL_MACHINE);
    m_hKeyBase = hKeyBase;
}


When called through the following callstack, the ASSERT(m_pWinApp != NULL); is fine :

>    XT4100Libd.dll!CXTRegistryManager::CXTRegistryManager(HKEY__ * hKeyBase=0x80000001)  Line 29    C++
     XT4100Libd.dll!CXTToolsManager::OnLoad()  Line 217 + 0xd bytes    C++
     XT4100Libd.dll!CXTToolsManager::Load()  Line 277 + 0xd bytes    C++
     XT4100Libd.dll!CXTToolsManager::CXTToolsManager()  Line 55 + 0x8 bytes    C++
     XT4100Libd.dll!CXTToolsManager::Get()  Line 637 + 0x28 bytes    C++
     XT4100Libd.dll!CXTFrameImpl::CXTFrameImpl()  Line 89 + 0x7 bytes    C++
     XT4100Libd.dll!CXTFrameWnd::CXTFrameWnd()  Line 70 + 0x48 bytes    C++
     Editor_d.dll!CMainFrame::CMainFrame()  Line 153 + 0x52 bytes    C++
     Editor_d.dll!CMainFrame::CreateObject()  Line 68 + 0x5c bytes    C++
     mfc90d.dll!CRuntimeClass::CreateObject()  Line 142 + 0x8 bytes    C++
     mfc90d.dll!CDocTemplate::CreateNewFrame(CDocument * pDoc=0x56ef5d38, CFrameWnd * pOther=0x00000000)  Line 262 + 0xb bytes    C++
     mfc90d.dll!CSingleDocTemplate::OpenDocumentFile(const char * lpszPathName=0x00000000, int bMakeVisible=1)  Line 125 + 0x13 bytes    C++
     mfc90d.dll!CDocManager::OnFileNew()  Line 848    C++
     mfc90d.dll!CWinApp::OnFileNew()  Line 22    C++
     Editor_d.dll!CNomadEditApp::InitEngine()  Line 2611    C++
     [Managed to Native Transition]   
     Editor_d.dll!Dunia::Interop::DuniaInterop::Initialize() Line 292 + 0x1e bytes    C++
     Dunia.Shell.exe!Dunia.Shell.MainWindow.Views.MainWindow.HostDuniaEditor() Line 94 + 0x11 bytes    C#
     Dunia.Shell.exe!Dunia.Shell.MainWindow.Views.MainWindow.MainWindow_Loaded(object sender = {Dunia.Shell.MainWindow.Views.MainWindow}, System.Windows.RoutedEventArgs e = {System.Windows.RoutedEventArgs}) Line 166 + 0x8 bytes    C#
     PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) + 0x78 bytes   
     PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {Dunia.Shell.MainWindow.Views.MainWindow}, System.Windows.RoutedEventArgs args = {System.Windows.RoutedEventArgs}, bool reRaised = false) + 0x1bf bytes   
     PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {Dunia.Shell.MainWindow.Views.MainWindow}, System.Windows.RoutedEventArgs args = {System.Windows.RoutedEventArgs}) + 0x79 bytes   
     PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs e) + 0x17 bytes   
     PresentationFramework.dll!System.Windows.BroadcastEventHelper.BroadcastEvent(System.Windows.DependencyObject root, System.Windows.RoutedEvent routedEvent = {System.Windows.RoutedEvent}) + 0x132 bytes   
     PresentationFramework.dll!System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(object root) + 0xa9 bytes   
     PresentationCore.dll!MS.Internal.LoadedOrUnloadedOperation.DoWork() + 0x16 bytes   
     PresentationCore.dll!System.Windows.Media.MediaContext.FireLoadedPendingCallbacks() + 0x71 bytes   
     PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() + 0x30 bytes   
     PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget = {System.Windows.Interop.HwndTarget}) + 0x80 bytes   
     PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget) + 0x2b bytes   
     PresentationCore.dll!System.Windows.Media.MediaContext.Resize(System.Windows.Media.ICompositionTarget resizedCompositionTarget) + 0x3b bytes   
     PresentationCore.dll!System.Windows.Interop.HwndTarget.OnResize() + 0x147 bytes   
     PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage(int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x21a bytes   
     PresentationCore.dll!System.Windows.Interop.HwndSource.HwndTargetFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled = false) + 0x3a bytes   
     WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 737116, int msg = 5, System.IntPtr wParam = 0, System.IntPtr lParam = 50332672, ref bool handled = false) + 0xbe bytes   
     WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x7a bytes   
     WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = Cannot evaluate expression because a native frame is on top of the call stack.}, object args = {MS.Win32.HwndSubclass.DispatcherOperationCallbackParameter}, bool isSingleParameter = true) + 0x8a bytes   
     WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) + 0x44 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) + 0x91 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x40 bytes   
     WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 737116, int msg = 5, System.IntPtr wParam = 0, System.IntPtr lParam = 50332672) + 0xdc bytes   
     [Frames below may be incorrect and/or missing, no symbols loaded for mscorwks.dll]   
     [Native to Managed Transition]   
     WindowsBase.dll!MS.Win32.HwndSubclass.DefWndProcWrapper(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x78 bytes   
     [Native to Managed Transition]   
     user32.dll!_InternalCallWinProc@20()  + 0x23 bytes   
     user32.dll!_UserCallWinProcCheckWow@32()  + 0xb7 bytes   
     user32.dll!_CallWindowProcAorW@24()  + 0x5e bytes   
     user32.dll!_CallWindowProcW@20()  + 0x1b bytes   
     [Managed to Native Transition]   
     WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x125 bytes   
     [Native to Managed Transition]   
     user32.dll!_InternalCallWinProc@20()  + 0x23 bytes   
     user32.dll!_UserCallWinProcCheckWow@32()  + 0xa65 bytes   
     user32.dll!_DispatchClientMessage@24()  + 0x51 bytes   
     user32.dll!___fnINLPWINDOWPOS@4()  + 0x2c bytes   
     ntdll.dll!776500e6()    
     user32.dll!_NtUserSetWindowRgn@12()  + 0x15 bytes   
     [Managed to Native Transition]   
     Microsoft.Windows.Shell.dll!Standard.NativeMethods.SetWindowRgn(System.IntPtr hWnd = 737116, System.IntPtr hRgn = -301715426, bool bRedraw = false) Line 3153 + 0x10 bytes    C#
     Microsoft.Windows.Shell.dll!Microsoft.Windows.Shell.WindowChromeWorker._SetRoundingRegion(Standard.WINDOWPOS? wp = null) Line 942    C#
     Microsoft.Windows.Shell.dll!Microsoft.Windows.Shell.WindowChromeWorker._UpdateFrameState(bool force = true) Line 810 + 0x32 bytes    C#
     Microsoft.Windows.Shell.dll!Microsoft.Windows.Shell.WindowChromeWorker._ApplyNewCustomChrome() Line 259    C#
     Microsoft.Windows.Shell.dll!Microsoft.Windows.Shell.WindowChromeWorker._SetWindow.AnonymousMethod(object sender = {Dunia.Shell.MainWindow.Views.MainWindow}, System.EventArgs e = {System.EventArgs}) Line 182 + 0x8 bytes    C#
     PresentationFramework.dll!System.Windows.Window.OnSourceInitialized(System.EventArgs e) + 0x7d bytes   
     PresentationFramework.dll!System.Windows.Window.CreateSourceWindowImpl() + 0x1b6 bytes   
     PresentationFramework.dll!System.Windows.Window.SafeCreateWindow() + 0x29 bytes   
     PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox) + 0x81 bytes   
     PresentationFramework.dll!System.Windows.Window.Show() + 0x48 bytes   
     Dunia.Shell.exe!Dunia.Shell.App.Application_Startup(object sender = {Dunia.Shell.App}, System.Windows.StartupEventArgs e = {System.Windows.StartupEventArgs}) Line 84 + 0x15 bytes    C#
     PresentationFramework.dll!System.Windows.Application.OnStartup(System.Windows.StartupEventArgs e) + 0x7a bytes   
     PresentationFramework.dll!System.Windows.Application..ctor.AnonymousMethod(object unused) + 0x29 bytes   
     WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = Cannot evaluate expression because a native frame is on top of the call stack.}, object args = null, bool isSingleParameter = true) + 0x8a bytes   
     WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) + 0x44 bytes   
     WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0x5d bytes   
     WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) + 0x38 bytes   
     mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x51 bytes   
     mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x67 bytes   
     mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x45 bytes   
     WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x63 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() + 0x127 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x63 bytes   
     WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 2047844, int msg = 49493, System.IntPtr wParam = 0, System.IntPtr lParam = 0, ref bool handled = false) + 0xbe bytes   
     WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x7a bytes   
     WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = Cannot evaluate expression because a native frame is on top of the call stack.}, object args = {MS.Win32.HwndSubclass.DispatcherOperationCallbackParameter}, bool isSingleParameter = true) + 0x8a bytes   
     WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) + 0x44 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) + 0x91 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x40 bytes   
     WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 2047844, int msg = 49493, System.IntPtr wParam = 0, System.IntPtr lParam = 0) + 0xdc bytes   
     [Native to Managed Transition]   
     user32.dll!_InternalCallWinProc@20()  + 0x23 bytes   
     user32.dll!_UserCallWinProcCheckWow@32()  + 0xb7 bytes   
     user32.dll!_DispatchMessageWorker@8()  + 0xed bytes   
     user32.dll!_DispatchMessageW@4()  + 0xf bytes   
     [Managed to Native Transition]   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame}) + 0xc4 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) + 0x49 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() + 0x4c bytes   
     PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) + 0x1e bytes   
     PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x6f bytes   
     PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) + 0x26 bytes   
     PresentationFramework.dll!System.Windows.Application.Run() + 0x19 bytes   
     Dunia.Shell.exe!Dunia.Shell.App.Main() + 0x5e bytes    C#
     mscoreei.dll!737f55ab()    
     mscoree.dll!73867f16()    
     mscoree.dll!73864de3()    
     kernel32.dll!76be3677()    
     ntdll.dll!77679f02()    

After clicking on a menu option, the same assert fails with the following callstack :

>    XT4100Libd.dll!CXTRegistryManager::CXTRegistryManager(HKEY__ * hKeyBase=0x80000001)  Line 29 + 0x21 bytes    C++
     XT4100Libd.dll!CXTCoolMenu::IsRecentItem(unsigned int nItem=483)  Line 2355 + 0xd bytes    C++
     XT4100Libd.dll!CXTCoolMenu::AddRecentItem(unsigned int nItem=483)  Line 2376 + 0x29 bytes    C++
     XT4100Libd.dll!CXTCoolMenu::WindowProc(unsigned int message=273, unsigned int wParam=483, long lParam=0)  Line 920    C++
     XT4100Libd.dll!CXTWindowMap::HookWndProc(HWND__ * hWnd=0x000c41a0, unsigned int message=273, unsigned int wParam=483, long lParam=0)  Line 136 + 0x19 bytes    C++
     user32.dll!_InternalCallWinProc@20()  + 0x23 bytes   
     user32.dll!_UserCallWinProcCheckWow@32()  + 0xb7 bytes   
     user32.dll!_DispatchMessageWorker@8()  + 0xed bytes   
     user32.dll!_DispatchMessageW@4()  + 0xf bytes   
     [Managed to Native Transition]   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame}) + 0xc4 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) + 0x49 bytes   
     WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() + 0x4c bytes   
     PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) + 0x1e bytes   
     PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x6f bytes   
     PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) + 0x26 bytes   
     PresentationFramework.dll!System.Windows.Application.Run() + 0x19 bytes   
     Dunia.Shell.exe!Dunia.Shell.App.Main() + 0x5e bytes    C#
     [Frames below may be incorrect and/or missing, no symbols loaded for mscorwks.dll]   
     mscoreei.dll!737f55ab()    
     mscoree.dll!73867f16()    
     mscoree.dll!73864de3()    
     kernel32.dll!76be3677()    
     ntdll.dll!77679f02()    



Back to Top
jojoba View Drop Down
Newbie
Newbie


Joined: 17 August 2011
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote jojoba Quote  Post ReplyReply Direct Link To This Post Posted: 23 August 2011 at 10:10am
Hi,

Judging by the amount of replies, it seems that my problem isn't a common one Wink.
I have investigated a bit more and I fell upon the following piece of code in XTFunctions.h :

#if defined(XT_INIT_BY_REGULAR_DLL)
//////////////////////////////////////////////////////////////////////
// Summary: This member function will initialize the resources for the Xtreme Toolkit.
//            If using the Xtreme Toolkit as an extension DLL within a regular DLL,
//            add the following two lines to your stdafx.h file. This will give you
//            access to the exported function InitXtremeExtDll():
//
//            <pre>#define XT_INIT_BY_REGULAR_DLL
//            #include "XTToolkit.h"</pre>
//
//            You will then need to add XT_INIT_BY_REGULAR_DLL to the Xtreme Toolkit
//            preprocessor definitions and rebuild it. After you have done this,
//            locate your CWinApp::InitInstance() method for your regular DLL and make
//            the following call:
//
//            <pre>InitXtremeExtDLL();</pre>
//
//            This will initialize the resources for the Xtreme Toolkit.
extern _XT_EXT_CLASS void WINAPI InitXtremeExtDLL();
#endif // defined(XT_INIT_BY_REGULAR_DLL)


As my change implied changing the compilation of the MFC code from an executable to a DLL, I guess the comment "If using the Xtreme Toolkit as an extension DLL within a regular DLL" applies to my case. I therefore did what was suggested :

- I've added :
#define XT_INIT_BY_REGULAR_DLL
#include <XTToolkit.h>

to my precompiled header file.

- I've recompiled XT4100Libd.dll and XT4100Libd.lib with the following preprocessor definitions :
_DEBUG
_AFXDLL
WIN32
_WINDOWS
_WIN32
_VC80_UPGRADE=0x0710
_MBCS
_XT_NO_MANAGED_STATE
_WINDLL
_XT_DLL
XT_INIT_BY_REGULAR_DLL


- I've called InitXtremeExtDll() in my app's ::InitInstance() function

Unfortunately, when recompiling, I get the following error :
1>Compiling...
1>NomadEdit.cpp
1>Automatically linking with XT4100Libd.dll
1>.\NomadEdit.cpp(2200) : error C3861: 'InitXtremeExtDLL': identifier not found

And indeed, when I look into the XT code, InitXtremeExtDLL is declared (provided XT_INIT_BY_REGULAR_DLL is defined) but never defined, unlike other global functions like _xtAfxChangeWindowFont, etc. Is this a remnant of a code that hasn't been removed ? Do I have an incomplete version of XT Toolkit ? If it was indeed defined, should I use this function ? And more importantly : do you think it's related to my initial problem of AfxGetApp and AfxGetResourceHandle returning NULL ?

Thank you for your help!

Jo
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.063 seconds.