Solved

Calling other applications within VB

Posted on 2000-04-06
8
134 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
Comment Utility
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
Comment Utility
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
Comment Utility
Well, if you just want to start it, why not use:

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

Expert Comment

by:ashunigam
Comment Utility
Are these standard EXE or ActiveX?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:AshokKumar
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks very much for your help, it's helped me loads!!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

15 Experts available now in Live!

Get 1:1 Help Now