using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WinTrisEx01
{
public partial class Form1 : Form
{
public const int WM_COPYDATA = 0x004A;
int xpos=0;
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr tailHandle = IntPtr.Zero;
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SendToTail(1, ">>>>SendData:[" + xpos.ToString("00000") + "]");
xpos++;
}
private void SendToTail(int index, string data)
{
tailHandle = FindWindow(null, "RecvSendDataMonitoring");
try
{
byte[] dataByte = Encoding.UTF8.GetBytes(data);
COPYDATASTRUCT copyData = new COPYDATASTRUCT();
copyData.dwData = (IntPtr)0;
copyData.cbData = data.Length;
copyData.lpData = Marshal.AllocHGlobal(dataByte.Length);
Marshal.Copy(dataByte, 0, copyData.lpData, dataByte.Length);
IntPtr sendData = Marshal.AllocHGlobal(Marshal.SizeOf(copyData));
Marshal.StructureToPtr(copyData, sendData, true);
IntPtr _result = SendMessage(tailHandle, WM_COPYDATA, (IntPtr)index, sendData);
Marshal.FreeHGlobal(copyData.lpData);
Marshal.FreeHGlobal(sendData);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
}
}
'c# 언어' 카테고리의 다른 글
this.Text = "베트남어: Ti?ng Thai"; (0) | 2021.12.25 |
---|---|
From FindWindow(), This Application is Detected!! The KeyWord is Below String (0) | 2021.12.25 |
From BackgroundWorker 매카니즘 (0) | 2021.12.24 |
From Process To Process, Message Send,Recv (0) | 2021.12.24 |
BackgroundWorker를 통해 안전하게 이벤트 기반으로 비동기 처리 (0) | 2021.12.23 |