The .NET ActiveX component with WPF content can't be loaded by non MFC app
I have a legacy delphi program and want to add some content implemented with WPF. So I encapsulate the WPF control with a .NET/ActiveX interop technology. That means something like:
[ComRegisterFunction()]
public static void RegisterClass(string key);
[ComUnregisterFunction()]
public static void UnregisterClass(string key);
The activeX component is a WinForms User Control and the WPF materials are attached to an ElemenHost in this User Control.
It works fine if the host app of this ActiveX is a MFC program even without /clr switch. But my legacy app is a de开发者_Go百科lphi program, and it always throw a stackoverflow exception at the first line of the constructor of my WPF user control as the program be started.
the message shows by exception is:
An unhandled exception of type 'System.StackOverflowException' occurred in PresentationFramework.dll
I have no clue, Google is no help. and it has puzzled me for days.
Wow! Delphi -> ActiveX -> WinForms -> WPF. I would be amazed if it actually worked.
My suggestion would be to get WinForms and ActiveX out of the picture entirely:
On the WPF side just:
- Use a HwndSource as your PresentationSource
- Create a class that exposes a "CreateWindow" function that takes an IntPtr to the parent window
- Apply [ComVisible] to the class
On the Delphi side just:
- Construct the parent window
- Create the WPF class using COM
- Call "CreateWindow" to create the WPF content
- Set other properties as needed to control and communicate with the WPF content
If you really want to try and make the Delphi -> ActiveX -> WinForms -> WPF nesting work, I would start by getting a stack trace at the time of the stack overflow. This should clue you in to what is going wrong and fix it.
精彩评论