0

I need solution for this requirement.

I 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.

venkat
  • 5,648
  • 16
  • 58
  • 83
  • Just to clarify: Application A passes a string value to Application B *which is already running*, then at a later time Application C retrieves that string value from Application B? – slugster Jan 12 '11 at 11:06

3 Answers3

1

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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
1

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

hungryMind
  • 6,931
  • 4
  • 29
  • 45
1

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

Nekresh
  • 2,948
  • 23
  • 28
  • Please provide me the code how to pass arguments/string content to the exe and again how i can retrieve the same using Process in C#. Provide me complete code. With the above one line of code i'm unable to get the data from exe. – venkat Jan 14 '11 at 06:33