Solved

Calling other applications within VB

Posted on 2000-04-06
8
145 Views
Last Modified: 2010-05-02
I have written 2 Vb projects and i want to call one from the other.  Is this easy and how is it done?
0
Comment
Question by:CRICE
8 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2690401
Do you want to start the other application, or do you want the applications to be able to communicate with each other?
0
 
LVL 20

Expert Comment

by:hes
ID: 2690524
In a module put:

Public Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Public Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type

Public Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long

Public Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
As Long

Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
As Long) As Long

Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&

In your code where you want to start the other application put:

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

'Initialize the STARTUPINFO structure:
start.cb = Len(start)

'Start the shelled application:
ret& = CreateProcessA(0&, "Your Other Program", 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

'Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2690551
Well, if you just want to start it, why not use:

Call Shell("c:\Project2.exe", vbNormalFocus)
0
 
LVL 3

Expert Comment

by:ashunigam
ID: 2690774
Are these standard EXE or ActiveX?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:AshokKumar
ID: 2692260
Yeah hes. y all these codings (Smile. Of course u have done a great job but . . . ) Erick37's code is enough to start an application. Or if u need to start a new instance of an existing application u can use this:

First give the reference in Project->reference
Then

Dim obj as object
Set Obj = CreateObject("MsWord.Application")

0
 

Author Comment

by:CRICE
ID: 2692598
Thank you all for your help, just one more thing before i allocate the points, what if i wanted to pass information from one application to the other. Like a parameter list.  
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2693249
Your application can process command line parameters.

eg, start the program like this

Call Shell("c:\Project2.exe x y z", vbNormalFocus)

In Projext2's form load you can read the command line switch(es) like this:

Dim sCmdLine As String
sCmdLine = Command

sCmdLine will contain the string "x y z" which you can parse using the Split function.

VB help has an example of reading the command line, search for "Command Line."
0
 

Author Comment

by:CRICE
ID: 2693264
Thanks very much for your help, it's helped me loads!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now