views:

125

answers:

1

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 delphi 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.

A: 

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.

Ray Burns
Thanks for your reply, I will try this way.About the stack trace, it is a infinite nested calling in 'ntdll.dll', no function name.