( LIKE ) COMMAND LINE ARGUMENT ... HOW?
NOT COMMAND LINE ARGUMENTS
Printable View
( LIKE ) COMMAND LINE ARGUMENT ... HOW?
NOT COMMAND LINE ARGUMENTS
well command line args only get passed when a program starts.. so if you were going to shell an app from another one.. you could pass arguments that way...
when your app starts up that is going to revieve arguments.. use the command$() function to get the passed in parameters.. you then have to parse them... thats why you notice programs that take command line parameters are usually like /s or -r
using a character like / or - makes it easy to parse...
there are other ways.. like using a database to share data.. or a text file..
or check out this link
http://www.thescarms.com/vbasic/PassString.asp
The Command$ variable in a VB program always has the command line parameters that were passed to the program.
Eg
If you call the program with
RunThis.EXE A B C
command$ will contain "A B C"
So.. if you want to pass information from one program to another in this way you can SHELL the second program from the first program..
eg; in program 1
Shell "Program2.EXE A B C"
in program 2
If Command$="A B C" then
..do something
end if
LIKE CHAT PROGRAM THE TWO PROGRAM HAVE TO PASS VALUES
-WHEN EVER IT NEEDS
now your talking about the winsock control...Quote:
Originally posted by vb cub
LIKE CHAT PROGRAM THE TWO PROGRAM HAVE TO PASS VALUES
-WHEN EVER IT NEEDS
http://216.26.168.92/vbworld/article.aspx?tag=winsock
tHANK YOU
Quote:
Originally posted by kleinma
well command line args only get passed when a program starts.. so if you were going to shell an app from another one.. you could pass arguments that way...
when your app starts up that is going to revieve arguments.. use the command$() function to get the passed in parameters.. you then have to parse them... thats why you notice programs that take command line parameters are usually like /s or -r
using a character like / or - makes it easy to parse...
there are other ways.. like using a database to share data.. or a text file..
or check out this link
http://www.thescarms.com/vbasic/PassString.asp
THANKS
This piece of Interprocess Communication was stolen from somewhere - probably from this forum, or from MS or MSDN.....
1. Create a file called frmReceive.frm
2. In Notepad paste the following into that file
3. In VB create a project called ReceiveStringCode:VERSION 5.00
Begin VB.Form frmReceive
BorderStyle = 1
Caption = "Receive String"
ClientHeight = 1590
ClientLeft = 45
ClientTop = 330
ClientWidth = 3210
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
ScaleHeight = 1590
ScaleWidth = 3210
Begin VB.CommandButton cmdQuit
Cancel = -1 'True
Caption = "&Quit"
Height = 375
Left = 1943
TabIndex = 2
Top = 986
Width = 975
End
Begin VB.Label lblString
BackColor = &H00FFFFFF&
BorderStyle = 1 'Fest Einfach
Height = 285
Left = 263
TabIndex = 1
Top = 469
Width = 2685
End
Begin VB.Label Label1
Caption = "Here is the string that was sent:"
Height = 255
Left = 263
TabIndex = 0
Top = 229
Width = 2415
End
End
Attribute VB_Name = "frmReceive"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdQuit_Click()
Unload Me
End Sub
Private Sub Form_Load()
' Get this form's handle.
' Subclass this form to trap Windows messages.
g_lnghWnd = Me.hwnd
Call Hook
Me.Left = Screen.Width / 5 * 4 - Me.Width
Me.Top = Screen.Height / 5 * 4 - Me.Height
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Un-subclass the form.
Call Unhook
Unload Me
Set frmReceive = Nothing
End Sub
4. Add frmReceive
5. Add the following code in a module
6. Compile into an exeVB Code:
Option Explicit Public g_lngPrevWndProc As Long Public g_lnghWnd As Long Public Const GWL_WNDPROC = (-4) Public Const WM_COPYDATA = &H4A Public Type COPYDATASTRUCT dwData As Long cbData As Long lpData As Long End Type ' Copies a block of memory from one location to another. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long) Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long ' ' Sub class the form to trap for Windows messages. ' Public Sub Hook() g_lngPrevWndProc = SetWindowLong(g_lnghWnd, GWL_WNDPROC, AddressOf WindowProc) Debug.Print g_lngPrevWndProc End Sub Public Sub ReceiveMsg(lngParam As Long) Dim strString As String Dim cds As COPYDATASTRUCT Dim bytBuffer(1 To 255) As Byte ' Copy the data sent to this application into a local structure. Call CopyMemory(cds, ByVal lngParam, Len(cds)) ' Copy the string that was passed into a byte array. Call CopyMemory(bytBuffer(1), ByVal cds.lpData, cds.cbData) ' Convert the ASCII byte array back to a Unicode string. strString = StrConv(bytBuffer, vbUnicode) strString = Left$(strString, InStr(1, strString, Chr$(0)) - 1) ' Display the received string. frmReceive.lblString = strString End Sub ' ' Remove the subclassing. ' Public Sub Unhook() Call SetWindowLong(g_lnghWnd, GWL_WNDPROC, g_lngPrevWndProc) End Sub Public Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long ' This callback routine is called by Windows whenever a message is sent to this form. If it is ' the copy message call our procedure to receive the message. If uMsg = WM_COPYDATA Then Call ReceiveMsg(lParam) ' Call the original window procedure associated with this form. WindowProc = CallWindowProc(g_lngPrevWndProc, hw, uMsg, wParam, lParam) End Function
7. Create a file called frmSend.frm
8. In Notepad paste the following into that file
9. Add this form to a new VB project called SendString and compile thatCode:VERSION 5.00
Begin VB.Form frmSend
BorderStyle = 1
Caption = "Send String"
ClientHeight = 1545
ClientLeft = 45
ClientTop = 330
ClientWidth = 3180
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
ScaleHeight = 1545
ScaleWidth = 3180
Begin VB.CommandButton cmdQuit
Cancel = -1 'True
Caption = "&Quit"
Height = 375
Left = 1943
TabIndex = 3
Top = 945
Width = 975
End
Begin VB.TextBox txtString
Height = 285
Left = 263
TabIndex = 1
Top = 465
Width = 2655
End
Begin VB.CommandButton cmdSend
Caption = "&Send String"
Height = 375
Left = 263
TabIndex = 0
Top = 945
Width = 1095
End
Begin VB.Label Label1
Caption = "Enter the string to send:"
Height = 255
Left = 263
TabIndex = 2
Top = 225
Width = 2175
End
End
Attribute VB_Name = "frmSend"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
ttribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Const WM_COPYDATA = &H4A
Private Type COPYDATASTRUCT
dwData As Long
cbData As Long
lpData As Long
End Type
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
' Copies a block of memory from one location to another.
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Sub cmdQuit_Click()
Unload Me
End Sub
Private Sub cmdSend_Click()
Dim strString As String
Dim lnghWnd As Long
Dim cds As COPYDATASTRUCT
Dim bytBuffer(1 To 255) As Byte
strString = Trim$(txtString.Text)
If strString = "" Then Exit Sub
' Get the handle of the target application.
lnghWnd = FindWindow(vbNullString, "Receive String")
' Copy the string into a byte array, converting it to ASCII. Assign lpData the address of the
' byte array.
Call CopyMemory(bytBuffer(1), ByVal strString, Len(strString))
With cds
.dwData = 3
.cbData = Len(strString) + 1
.lpData = VarPtr(bytBuffer(1))
End With
' Send the string.
Call SendMessage(lnghWnd, WM_COPYDATA, Me.hwnd, cds)
End Sub
Private Sub Form_Load()
Me.Left = Screen.Width / 5
Me.Top = Screen.Height / 5
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Me
Set frmSend = Nothing
End Sub
10. Run them both and Bob's your uncle
if he wants a chat program then winsock is def the way to go