Click here to Skip to main content
15,914,013 members
Home / Discussions / C#
   

C#

 
GeneralRe: User Control Pin
Christian Graus1-Feb-07 20:28
protectorChristian Graus1-Feb-07 20:28 
AnswerRe: User Control Pin
aSarafian1-Feb-07 2:15
aSarafian1-Feb-07 2:15 
GeneralRe: User Control Pin
Biswajit Ghosh1-Feb-07 19:48
Biswajit Ghosh1-Feb-07 19:48 
GeneralRe: User Control Pin
aSarafian1-Feb-07 21:16
aSarafian1-Feb-07 21:16 
AnswerRe: User Control Pin
Luc Pattyn1-Feb-07 7:16
sitebuilderLuc Pattyn1-Feb-07 7:16 
GeneralRe: User Control Pin
Biswajit Ghosh1-Feb-07 19:47
Biswajit Ghosh1-Feb-07 19:47 
GeneralRe: User Control Pin
Luc Pattyn1-Feb-07 23:41
sitebuilderLuc Pattyn1-Feb-07 23:41 
QuestionHow to use WM_COPYDATA to send a struct to another process? Pin
huheng_0_031-Jan-07 20:14
huheng_0_031-Jan-07 20:14 
for example:
//---------------------------------------------
// Sender
//---------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WinFormSendMsg
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
const int WM_COPYDATA = 0x004A;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(12, 70);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(205, 231);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 32);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6F, 13F);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.textBox1
this.textBox2});
this.Name = "Form1";
this.Text = "Sender";
this.ResumeLayout(false);
}

static void Main()
{
Application.Run(new Form1());
}
[DllImport("User32.dll",EntryPoint="SendMessage")]
private static extern int SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
ref COPYDATASTRUCT lParam // second message parameter
);

[DllImport("User32.dll",EntryPoint="FindWindow")]
private static extern int FindWindow(string lpClassName,string
lpWindowName);

private void button1_Click(object sender, System.EventArgs e)
{
int WINDOW_HANDLER = FindWindow(null,@"Accepter");
if(WINDOW_HANDLER == 0)
{
}
else
{
COPYDATASTRUCT cds;
cds.dwData = (IntPtr) 100;
WholeInfo wi = new WholeInfo();
wi.m_centralFilePath = this.textBox1.Text;
wi.m_localFilePath = this.textBox2.Text;
cds.cbData = Marshal.SizeOf(wi);
IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(wi));
Marshal.StructureToPtr(wi, p, true);
cds.lpData = p;
SendMessage(WINDOW_HANDLER, WM_COPYDATA, 0, ref cds);
}
}
}
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
public struct WholeInfo
{
public String m_centralFilePath;
public String m_localFilePath;
};
}


//------------------------------------------------------------
//Accepter:
//------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsFormGetMsg
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.Container components = null;
const int WM_COPYDATA = 0x004A;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(12, 70);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(432, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1
this.textBox2});
this.Name = "Form1";
this.Text = "Accepter";
this.ResumeLayout(false);
}
static void Main()
{
Application.Run(new Form1());
}
protected override void DefWndProc(ref System.Windows.Forms.Message m)
{
switch(m.Msg)
{
case WM_COPYDATA:
COPYDATASTRUCT mystr = new COPYDATASTRUCT();
Type mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
WholeInfo h;
h = (WholeInfo)Marshal.PtrToStructure(mystr.lpData, typeof(WholeInfo));
this.textBox1.Text = h.m_centralFilePath;
this.textBox2.Text = h.m_localFilePath;
break;
default:
base.DefWndProc(ref m);
break;
}
}
}
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
public struct WholeInfo
{
public String m_centralFilePath;
public String m_localFilePath;
};
}

-------------------------------------------------------------------------
above is my test code, but there are some problem,sometimes it will crash, sometimes the Accepter Form's textBox1 and textBox2.Text display null or other error letter,never correct!
If any boy know the method to solve those problem,please teach me, it is better to give out the right code,full of thanks!


JimmyHu
AnswerRe: How to use WM_COPYDATA to send a struct to another process? Pin
Luc Pattyn1-Feb-07 7:38
sitebuilderLuc Pattyn1-Feb-07 7:38 
GeneralRe: How to use WM_COPYDATA to send a struct to another process? Pin
huheng_0_01-Feb-07 17:56
huheng_0_01-Feb-07 17:56 
GeneralRe: How to use WM_COPYDATA to send a struct to another process? Pin
Luc Pattyn2-Feb-07 9:41
sitebuilderLuc Pattyn2-Feb-07 9:41 
QuestionHELP: how to select specific node in XML using c# Pin
drifters31-Jan-07 20:13
drifters31-Jan-07 20:13 
AnswerRe: HELP: how to select specific node in XML using c# Pin
Christian Graus31-Jan-07 20:27
protectorChristian Graus31-Jan-07 20:27 
GeneralRe: HELP: how to select specific node in XML using c# Pin
drifters31-Jan-07 20:32
drifters31-Jan-07 20:32 
GeneralRe: HELP: how to select specific node in XML using c# [modified] Pin
bobsugar22231-Jan-07 22:19
bobsugar22231-Jan-07 22:19 
GeneralRe: HELP: how to select specific node in XML using c# [modified] Pin
drifters31-Jan-07 22:32
drifters31-Jan-07 22:32 
GeneralRe: HELP: how to select specific node in XML using c# Pin
Stefan Troschuetz31-Jan-07 22:33
Stefan Troschuetz31-Jan-07 22:33 
GeneralRe: HELP: how to select specific node in XML using c# Pin
drifters1-Feb-07 14:51
drifters1-Feb-07 14:51 
GeneralRe: HELP: how to select specific node in XML using c# Pin
drifters1-Feb-07 16:20
drifters1-Feb-07 16:20 
GeneralRe: HELP: how to select specific node in XML using c# Pin
Stefan Troschuetz1-Feb-07 20:56
Stefan Troschuetz1-Feb-07 20:56 
QuestionCall Java Code Pin
Expert Coming31-Jan-07 20:03
Expert Coming31-Jan-07 20:03 
AnswerRe: Call Java Code Pin
blackjack215031-Jan-07 20:15
blackjack215031-Jan-07 20:15 
Questioncombobox selectedindexchanged event Pin
KrunalC31-Jan-07 19:46
KrunalC31-Jan-07 19:46 
QuestionInterprocess communication using impersonation Pin
ParimalaRadjaram31-Jan-07 19:42
ParimalaRadjaram31-Jan-07 19:42 
QuestionHow to make an User Control in VC# that can be used in VC6? Pin
Andy Rama31-Jan-07 18:42
Andy Rama31-Jan-07 18:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.