Hosting a VFP App


Author
Message
Troy Murphy
Troy Murphy
StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)
Group: Forum Members
Posts: 12, Visits: 1.1K

I am trying to host an VFP application (MDI application withing the _screen) in .NET.

What am I doing wrong below?  When I run this and step into the Process.Start method, everything works fine.  However, when I run the code without a break-point, the VFP Application is not hosted.

A second question is: What would be the best practice in managing the process?  In other words: I would like the hosted application to terminate when the .NET app is exited.  Currently, unless I close the VFP app 1st, it is left in the running process collection (task manager).

 

Private Sub DocMgrToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DocMgrToolStripMenuItem.Click

Dim AppPath As String = "c:\MyVfpAppFolder\"

Dim App2Run As String = "MyGreatFoxProApp.exe"

Dim loStart As New System.Diagnostics.ProcessStartInfo(AppPath + App2Run)

loStart.WindowStyle = Diagnostics.ProcessWindowStyle.Normal

'loStart.UseShellExecute = False

loStart.WorkingDirectory = AppPath

Dim oProcess As System.Diagnostics.Process = System.Diagnostics.Process.Start(loStart)

'oProcess.WaitForInputIdle(3000)

Do While oProcess.MainWindowHandle.ToInt32() = 0

Loop

Dim lnHandle As Integer = oProcess.MainWindowHandle.ToInt32()

SetParent(lnHandle, Me.Handle)

End Sub


Replies
Troy Murphy
Troy Murphy
StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)StrataFrame Beginner (26 reputation)
Group: Forum Members
Posts: 12, Visits: 1.1K
Very impressive - I must say!  I wish there was a shortcut to learning the .NET stuff. 

Anyway, using your provided example I have been able to test most of the needed functionality, but I do have a question on the UDP communication:  If I send a message via MyMainForm (I made the UDP stuff public) in the sample CHILD .NET form as below - an "Object reference not set to an instance..." exception occurs at the "_UDP.Send(..." line in SendMessage method of UdpSession.vb and the _UDP object is null. 

Obviously I am trying to leverage the code from MyMainForm to pass messages to and from both applications.  Is this going about it the wrong way? 

MyMainForm._UDP.SendMessage(UDPMessageType.VisualFoxProCommand, "ChangeActiveCaseTo('" + CaseNo + "')")


Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Hey Troy,

I am glad that you are getting this going.  I am sure that you have learned that there are some frustrations making the two talk, but at least there is a solution!

As for your question, it just looks to me like you are attempting to reference the _UDP variable before it has been referenced.

Generally you should never directly reference a variable in another class like this.  Instead of making the _UDP property public, you should leave this private and then create a public property that exposes this variable.  You can also make it shared so you do not have to have a direct reference to the main form.  This will also require that the variable is shared and will require all of your current referneces as well to reference the shared property rather than the internal variable.

Private Shared _UDP As UDPSession
Public Shared ReadOnly Property UDP As UDPSession
    Get
        '-- Make sure the UDP object has been created
        If _UDP Is Nothing
             _UDP = New UDPSession(...)
        End If
    End Get
End Property

If you choose not to make the property shared and are going to just pass over a reference to any form that references the UDP property then the property would look something like this:

Private _UDP As UDPSession
Public ReadOnly Property UDP As UDPSession
    Get
        '-- Make sure the UDP object has been created
        If _UDP Is Nothing
             _UDP = New UDPSession(...)
        End If
    End Get
End Property

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search