Running one app from another

jswota

Well-known member
Joined
Feb 23, 2009
Messages
49
Programming Experience
Beginner
I have created a drawing viewer that displays CNC files. The viewer itself is a user control that i have compiled into a dll. I added a reference to this dll to a windows application and added the control to one of the forms. I also have a reference to other custom dll's within this project. The application works exactly as expected. CNC files can be viewed by using the File>Open menu. You can open a single file or load multiple files into a buffer that will allow you to scan through them using Next and Previous buttons.

What i want to do is open this viewer from another application but have certain CNC files already loaded into the viewer. I know i could get this working but i don't think it would be the best way. Is there a way for me to include a list of files in a shell command? Perhaps the enitre viewer application should be included in a dll that has a LoadFiles() and Show() method.

I would really appreciate any advice.

Thanks,
Joel
 
Could you call your program and then add the files to open as command line arguements? Like c:\MyAppDirectory\MyApp.exe "FirstFile" "SecondFile" then call something like this from your form load routine:

VB.NET:
   Friend Function CheckForCommandLineArguement() As String
        If My.Application.CommandLineArgs.Count > 0 Then
            Return My.Application.CommandLineArgs.ToString
        End If
        Return ""
    End Function
 
Thanks Sprint.

That exactly what i've been looking for. I just had no idea how to detect arguments that are passed in the shell statement.

My.Application.CommandLineArgs. Who knew?!?

Thanks.
 
Sure. If you want to get really fancy you can do something like this in your form load routine along with the above code

Dim myFilesToOpen As String() = Split(CheckForCommandLineArguement, " ")
For Each myFile As String In myFilesToOpen
OpenFile(myFile)
Next

Where OpenFile is the routine you use to open files.
 
Return My.Application.CommandLineArgs.ToString
This returns the string "System.Collections.ObjectModel.ReadOnlyCollection`1[System.String]", which is the type name, so the object CommandLineArgs function returns is a (readonly) string collection you can loop.
VB.NET:
For Each argument As String In My.Application.CommandLineArgs

Next
Also note the help remarks:
For a single-instance application, the My.Application.CommandLineArgs property returns the command-line arguments for the first instance of an application. To access the arguments for subsequent attempts to start a single-instance application, you must handle the My.Application.StartupNextInstance Event and examine the CommandLine property of the StartupEventArgs argument.
 
Back
Top