Hi,

I wonder how it would be possible to set a "string" in another application. I know the "MainWindowTitle" as my code goes below but I dont know how to set the text in one textBox that exists there. The thing I have to start with is the below but dont know how to continue from here.

I dont know the names of the textBox on "someSoftware"

        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hWnd, int wMsg, int
        wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam);
        private const int WM_SETTEXT = 0x0C;

        private void button8_Click(object sender, EventArgs e)
        {
            foreach (Process p in Process.GetProcesses())
            {
                String applicationName = p.MainWindowTitle.ToString().ToLower();

                if (applicationName.IndexOf("someSoftware") != -1)
                {
                    string txt = "Hello World";
                    IntPtr hWnd = p.Handle;


                    SendMessage(hWnd, WM_SETTEXT, 0, txt);
                    break;
                }
            }
        }

There are several way to share data beween applications. I would suggest communication via a port (UDPCLient for instance, easy to implement).

Shared memory is a solution when you have important volume of data to exchange (bitmap) but I fear you have to write a dll in non managed code for this.

You can try the Clipboard class that allow to write and read the containt of the clipboard. It is very simple to implement but I am a little suspicious with using the clipboard because it is shared by all applications.

Using shared memory is very easy in C#, no need for unmanaged code. Just do a search on memory mapped files.

But I believe the original poster is trying to create software to automate something he doesn't have the source for, such as a game.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.