|
-
Aug 25th, 2000, 01:55 PM
#1
Thread Starter
Lively Member
Does anyone know of a way to pass a return value through an executable? I would like to create a VB .exe program and call it from another program and pass a 1 or 0 back to the calling program. I know how to return with errorlevels which would work if I want to call it from a DOS batch file, but I was wondering if anyone knows of a different way!?
-
Aug 25th, 2000, 02:16 PM
#2
Just an idea
I don't know how to actually return a value, but maybe you can put a simple control on the calling form, like a command button, or a label, and set it's Visible property to False.
Then, add another argument to the program being called, and pass it the hWnd of the control. Then use SendMessage to pass the control either 0 or 1.
Eg:
Add this to the calling app:
Code:
Private Sub cmdArgReturn_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 0 Then
'Enter code
ElseIf KeyCode = 1 Then
'Enter code
End If
End Sub
And to the program that returns the value, add this:
To a module:
Code:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_KEYDOWN = &H100
And to where you want the call with the returned value:
Code:
'ValToReturn is either 1 or 0
'hWnd is the hWnd of the control on the othe app
SendMessage hWnd, WM_KEYDOWN, ValToReturn, 1
I didn't try it yet, but it should work. Maybe not in the first try, but after some tweaking it will work.
I hope this helps.
-
Aug 25th, 2000, 02:44 PM
#3
Fanatic Member
Do you know how to use the Windows clipboard from VB?
I think the easiest way would be for the calling program to first retrieve and store the data on the clipboard (if any) and then place its own data on the clipboard, and call the second program. The called program draws the data from the clipboard and passes its return value there. The original caller gets the data from the clipboard and places the original data there.
This scheme might be distrubed by the user or other applications of course, but it depends on how "critical" this app is.
You could alternatively create a temporary registry entry, use a temporary file, or maybe even pointers to memory locations, API calls etc. There are many ways. Of course, what about command line parameters?
-
Aug 25th, 2000, 02:45 PM
#4
Monday Morning Lunatic
Your second app can also send a message (using SendMessage) to the first app's main window.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|