I need solution for this requirement.
开发者_如何学JAVAI want to pass a string(or textbox1.text) value to my current running application exe. Then later in another project by running a process i want to retrieve the string contents from that exe. I'll do further validations with that string content/msg.
Please provide me with code how can i achieve this requirement in C#.NET terminology easily.
As I understant, you wan't to pass a string from one executable to another. You can do that by using Process's arguments :
System.Diagnostics.Process.Start("executable", "arg1 arg2 \"string with space as arg3\"");
The argument part must conform to the command line format, each argument is separated by space and you can have an argument with spaces by delimiting it with double quote (")
In your new process, you can retrieve theses arguments in your Main method
static void Main(string[] args)
In there, args[0]
will be equal to arg1
, args[0]
to arg2
and args[2]
to string with space as arg3
Use IPC.
A simple one could be to exchange data through the file system.
Application A could write to file A.TXT and application B could write to file B.TXT.
Then, application A can watch for changes of file B.TXT and application B can watch for changes in A.TXT.
Load the file into your application when changes occur and process the read content.
Better approach is to store these value in shared objects.
Alternative is to use interop FindWindow, and take the handle of textbox and read the contents
Private Declare Auto Function FindWindow Lib "user32.dll" ( _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpClassName As
String, _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpWindowName As
String _
) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32.dll" ( _
ByVal hWndParent As IntPtr, _
ByVal hWndChildAfter As IntPtr, _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpszClass As
String, _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpszWindow As
String _
) As IntPtr
Dim hWnd As IntPtr = FindWindow(vbNullString, "FSM")
If hWnd.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndButton As IntPtr = _
FindWindowEx(hWnd, IntPtr.Zero, "BUTTON", "Button 1")
If hWndButton.Equals(IntPtr.Zero) Then
Return
End If
....
///
Modify "BUTTON" to win32 text box class name. Try this VB code
精彩评论