Host a Delphi 7 application process in .net

HI! I'm trying to host a delphi 7 vcl application in a .Net wpf application. Everything works great except modal dialogs do not behave like modal dialogs, the parent window isn't disabled. This is my code so far:

   class MySimpleDelphiHost : HwndHost
      private Process _appProc;
      public IntPtr hwndHost;

      protected override HandleRef BuildWindowCore(HandleRef hwndParent)
         _appProc = new Process();
         _appProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
         _appProc.StartInfo.FileName = @"MySimpleDelphiApplication.exe";
         hwndHost = Win32API.FindWindow("TMainForm", null);
         int oldStyle = Win32API.GetWindowLong(hwndHost, Win32API.GWL_STYLE);
         Win32API.SetWindowLong(hwndHost, Win32API.GWL_STYLE, (oldStyle | Win32API.WS_CHILD) & ~Win32API.WS_BORDER);

         Win32API.SetParent(hwndHost, hwndParent.Handle);
         Win32API.ShowWindowAsync(hwndHost, Win32API.SW_SHOWMAXIMIZED);

         return new HandleRef(this, hwndHost);

      protected override void DestroyWindowCore(HandleRef hwnd)

If I host a none delphi application this works just fine. Any ideas?

I created a demo . Sorry for the hosting site.


FWIW have you tried setting:

Form.ModalPopupMode = pmExplicit;
Form.ModalParent = ParentForm;

Also you don't have to change tApplication in the Forms unit, you could do

  OldWndProc: Pointer; 

function NewWndProc(Handle: hWnd; Msg: UINT; PW: WPARAM; PL: LPARAM): LRESULT stdcall; 
  if Msg = WM_ENABLED then 
     result := 1; // handled
  end else 
  result := CallWindowProc(OldWndProc, Handle, Msg, PW, PL); 

  OldWndProc := Pointer(SetWindowLong(Application.Handle, GWL_WNDPROC,    

Need Your Help

Android - Adding tabs to a Fragment

android android-fragments tabs android-tabhost fragment-tab-host

I am making a Fragment with tabs but I am having a problem that I cannot resolve. When adding the tabs I must set a content with setContent() but I just can set an Activity or a layout and I want t...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.