define class MyAuto as custom OLEPUBLIC nThreadId = 0 oFormRef = NULL procedure Init declare integer GetCurrentThreadId in win32api This.nThreadId = GetCurrentThreadId() endproc procedure CreateFormInstance This.oFormRef = CreateObject("testform") This.oFormRef.Visible = .T. endproc && MyForm() procedure ProcessForm read events endproc && ProcessForm() enddefine && MyAuto::Custom define class testform as Form ShowWindow = 2 Caption = "Test Form" add object txtSurname as textbox with ; Top = 10, ; Left = 10, ; Width = 100, ; FontName = "Tahoma", ; FontSize = 8, ; Caption = "\<Close", ; Name = "txtSurname" add object cmdClose as commandbutton with ; Top = 213, ; Left = 283, ; Height = 27, ; Width = 84, ; FontName = "Tahoma", ; FontSize = 8, ; Caption = "\<Close", ; Name = "cmdClose" procedure cmdClose.Click clear events ThisForm.Visible = .F. endproc && cmdClose.Click() enddefine && testform::FormNow the following example will instantiate an instance of our COM server class and temporarily synchronise both threads (client and the server) input processing and bring the automation window to the front.
LOCAL loException as Exception LOCAL llError LOCAL loTest declare integer AttachThreadInput in win32api integer, integer, integer declare integer GetCurrentThreadId in win32api declare integer BringWindowToTop in win32api integer llError = .F. try loTest = CreateObject("test.myauto") catch to loException MessageBox(loException.Message, 16, "Test") llError = .T. finally if llError = .F. loTest.CreateFormInstance() if AttachThreadInput(loTest.nThreadId, GetCurrentThreadId(), 1) > 0 = BringWindowToTop(loTest.oFormRef.Hwnd) = AttachThreadInput(loTest.nThreadId, GetCurrentThreadId(), 0) loTest.ProcessForm() MessageBox("Surname=" + loTest.oFormRef.txtSurname.Value) else MessageBox("Could not attach to out-of-process server thread") endif loTest = NULL endif endtryThe order of events is important but I think this gives you a good starting point. Also, you don't have to use the BringWindowToTop API function, you could also use the SetFocus API function.