本文整理汇总了C#中COPYDATASTRUCT类的典型用法代码示例。如果您正苦于以下问题:C# COPYDATASTRUCT类的具体用法?C# COPYDATASTRUCT怎么用?C# COPYDATASTRUCT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
COPYDATASTRUCT类属于命名空间,在下文中一共展示了COPYDATASTRUCT类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SendMessage
public static void SendMessage(IntPtr hWnd, string message)
{
BinaryFormatter b = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
b.Serialize(stream, message);
stream.Flush();
// Now move the data into a pointer so we can send
// it using WM_COPYDATA:
// Get the length of the data:
int dataSize = (int)stream.Length;
if (dataSize > 0)
{
byte[] data = new byte[dataSize];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(data, 0, dataSize);
IntPtr ptrData = Marshal.AllocCoTaskMem(dataSize);
Marshal.Copy(data, 0, ptrData, dataSize);
COPYDATASTRUCT cds = new COPYDATASTRUCT();
cds.cbData = dataSize;
cds.dwData = IntPtr.Zero;
cds.lpData = ptrData;
int res = SendMessage(hWnd, WM_COPYDATA, 0, ref cds);
// Clear up the data:
Marshal.FreeCoTaskMem(ptrData);
}
stream.Close();
}
开发者ID:xwiz,项目名称:WixEdit,代码行数:31,代码来源:CopyDataMessenger.cs
示例2: Send
public static int Send(string data, IntPtr windowHandle)
{
var cds = new COPYDATASTRUCT();
cds.dwData = (IntPtr)Marshal.SizeOf(cds);
cds.cbData = (IntPtr)data.Length;
cds.lpData = Marshal.StringToHGlobalAnsi(data);
var ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(cds));
Marshal.StructureToPtr(cds, ptr, true);
try
{
const int WM_COPY_DATA = 0x004A;
var result = SendMessage(windowHandle, WM_COPY_DATA, IntPtr.Zero, ptr);
return result;
}
catch (Exception)
{
return 1;
}
finally
{
Marshal.FreeHGlobal(cds.lpData);
Marshal.FreeCoTaskMem(ptr);
}
}
开发者ID:jhorv,项目名称:Markdown-Edit,代码行数:26,代码来源:OldSchool.cs
示例3: WndProc
/// <summary>
/// Override for a form's Window Procedure to handle WM_COPYDATA
/// messages sent by other instances of this class.
/// </summary>
/// <param name="m">The Windows Message information.</param>
protected override void WndProc (ref System.Windows.Forms.Message m )
{
if (m.Msg == WM_COPYDATA)
{
COPYDATASTRUCT cds = new COPYDATASTRUCT();
cds = (COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
if (cds.cbData > 0)
{
byte[] data = new byte[cds.cbData];
Marshal.Copy(cds.lpData, data, 0, cds.cbData);
MemoryStream stream = new MemoryStream(data);
BinaryFormatter b = new BinaryFormatter();
CopyDataObjectData cdo = (CopyDataObjectData) b.Deserialize(stream);
if (channels.Contains(cdo.Channel))
{
DataReceivedEventArgs d = new DataReceivedEventArgs(cdo.Channel, cdo.Data, cdo.Sent);
OnDataReceived(d);
m.Result = (IntPtr) 1;
}
}
}
else if (m.Msg == WM_DESTROY)
{
// WM_DESTROY fires before OnHandleChanged and is
// a better place to ensure that we've cleared
// everything up.
channels.OnHandleChange();
base.OnHandleChange();
}
base.WndProc(ref m);
}
开发者ID:heon21st,项目名称:flashdevelop,代码行数:37,代码来源:CopyData.cs
示例4: SendMessageTimeout
public static extern int SendMessageTimeout(
IntPtr hwnd,
uint wMsg,
IntPtr wParam,
ref COPYDATASTRUCT lParam,
SendMessageTimeoutFlags flags,
uint timeout,
out IntPtr result);
开发者ID:TheCodeKing,项目名称:XDMessaging.Net,代码行数:8,代码来源:Native.cs
示例5: ReciveMessage
public static string ReciveMessage(ref Message m)
{
COPYDATASTRUCT mystr = new COPYDATASTRUCT();
Type mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
string data = mystr.lpData;
Debug.WriteLine("WM_COPYDATA message:" + data);
return data;
}
开发者ID:johnturek,项目名称:SipCommunicator,代码行数:9,代码来源:InterProcessCommunication.cs
示例6: OnCopyData
private void OnCopyData(ref Message m)
{
// Get the COPYDATASTRUCT
COPYDATASTRUCT cds = new COPYDATASTRUCT();
cds = (COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
// The lpData member of COPYDATASTRUCT points to an (unmanaged) FILECONTEXT struct
FILECONTEXT ht = (FILECONTEXT)Marshal.PtrToStructure(cds.lpData, typeof(FILECONTEXT));
string strTemp;
// If the target application opened, created, wrote to, or read from a file...
if (cds.dwData >= (int)FileAction.File_CreateAlways && cds.dwData <= (int) FileAction.File_Read)
{
int unManagedSize = Marshal.SizeOf(typeof(FILECONTEXT));
unsafe
{
byte* pString = (byte*)cds.lpData.ToPointer();
pString += unManagedSize;
IntPtr pManString = new IntPtr((void*)pString);
strTemp = Marshal.PtrToStringUni(pManString);
}
if (cds.dwData <= 5)
{
ListViewItem[] lvs = listOpenFiles.Items.Find(strTemp, true);
if (lvs == null || lvs.Length == 0)
{
ListViewItem lv = listOpenFiles.Items.Insert(listOpenFiles.Items.Count, strTemp);
lv.Tag = ht.Handle;
lv.Name = strTemp;
}
}
else
{
int nIndex = strTemp.IndexOf('\n');
if (nIndex > -1)
{
string Intro = strTemp.Substring(0, nIndex);
string Other = strTemp.Substring(nIndex);
Font oldFont = richFileOps.SelectionFont;
richFileOps.SelectionFont = _boldFont;
richFileOps.SelectedText = Intro;
richFileOps.SelectionFont = oldFont;
richFileOps.Select(richFileOps.TextLength, 0);
richFileOps.SelectedText = Other;
}
}
m.Result = (IntPtr)1;
}
// If the target application CLOSED a file
else if (cds.dwData == (int)FileAction.File_Close)
{
// TODO: remove the file from the GUI
}
}
开发者ID:DjPasco,项目名称:Mag,代码行数:56,代码来源:Form1.cs
示例7: _SendMessage
public static void _SendMessage(string msg, IntPtr target)
{
byte[] b = Encoding.UTF8.GetBytes(msg);
IntPtr hLog = Marshal.AllocHGlobal(b.Length);
Marshal.Copy(b, 0, hLog, b.Length);
COPYDATASTRUCT data = new COPYDATASTRUCT();
data.cbData = b.Length;
data.lpData = hLog;
SendMessage(target, WM_COPYDATA, 0, ref data);
}
开发者ID:Raymai97,项目名称:Win10ThemeRevealer,代码行数:10,代码来源:Win32.cs
示例8: Send
///<summary>Send the message to another process (receiver) using WM_COPYDATA.</summary>
///<param name="hHost">Handle of the receiver</param>
///<param name="msg">Message to be sent</param>
///<param name="port">Port on which to send the message</param>
public bool Send(IntPtr hHost, string msg, int port)
{
COPYDATASTRUCT cd = new COPYDATASTRUCT();
cd.dwData = port;
cd.cbData = msg.Length+1;
cd.lpData = Marshal.StringToHGlobalAnsi(msg).ToInt32();
//IntPtr pcd = Marshal.AllocCoTaskMem(Marshal.SizeOf(cd)); // Alocate memory
//Marshal.StructureToPtr(cd, pcd, true); // Converting structure to IntPtr
int i = SendMessage(hHost, WM_COPYDATA, id, ref cd);
return i==1 ? true : false;
}
开发者ID:majkinetor,项目名称:FormsFramework,代码行数:16,代码来源:IPC.cs
示例9: Send
///<summary>Send the textual message to another process (receiver).</summary>
///<param name="Hwnd">Handle of the receiver</param>
///<param name="Text">Message to be sent</param>
///<param name="Port">Port on which to send the message, positive integer</param>
public bool Send(IntPtr Hwnd, string Text, int Port)
{
COPYDATASTRUCT cd = new COPYDATASTRUCT();
cd.dwData = (IntPtr)(-Port); //use negative port for textual messages
cd.cbData = Text.Length + 1;
cd.lpData = Marshal.StringToHGlobalAnsi(Text);
//IntPtr pcd = Marshal.AllocCoTaskMem(Marshal.SizeOf(cd)); // Alocate memory
//Marshal.StructureToPtr(cd, pcd, true); // Converting structure to IntPtr
int i = SendMessage(Hwnd, WM_COPYDATA, this.Handle, ref cd);
return i==1 ? true : false;
}
开发者ID:majkinetor,项目名称:FormsFramework,代码行数:16,代码来源:IPC.cs
示例10: Send
static void Send(Params @params)
{
var copyDataMem = IntPtr.Zero;
var dataPointer = IntPtr.Zero;
try
{
var dataSize = 0;
dataPointer = IntPtr.Zero;
if (@params.Send.Data != null)
{
// Same algorithm to determine size as in Marshal.StringToHGlobalUni.
dataSize = (@params.Send.Data.Length + 1) * 2;
dataPointer = Marshal.StringToHGlobalUni(@params.Send.Data);
}
var copyData = new COPYDATASTRUCT
{
dwData = new UIntPtr(@params.Send.Message),
cbData = dataSize,
lpData = dataPointer
};
copyDataMem = Marshal.AllocHGlobal(Marshal.SizeOf(copyData));
Marshal.StructureToPtr(copyData, copyDataMem, true);
var result = NativeMethods.SendMessage(@params.Connection.Handle,
NativeConstants.WM_COPYDATA,
@params.Receiver.Handle,
copyDataMem);
if (result == IntPtr.Zero)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
RxMessageBrokerMinimod.Default.Send(new Log("Sent message {0} to MPC", @params.Send.Info()));
}
catch (Exception ex)
{
RxMessageBrokerMinimod.Default.Send(new Log("Failed to send message {0} to MPC: {1}",
@params.Send.Info(),
ex.Message));
}
finally
{
if (copyDataMem != IntPtr.Zero)
{
Marshal.FreeHGlobal(copyDataMem);
}
if (dataPointer != IntPtr.Zero)
{
Marshal.FreeHGlobal(dataPointer);
}
}
}
开发者ID:agross,项目名称:mpc-deleter,代码行数:53,代码来源:SendMessageHandler.cs
示例11: WndProc
protected override void WndProc(ref Message m)
{
if((m.Msg==WM_COPYDATA) && (m.WParam == id))
{
CD = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));
strData = Marshal.PtrToStringAnsi(new IntPtr(CD.lpData), CD.cbData);
if (OnMessage != null)
OnMessage( strData, CD.dwData );
return;
}
base.WndProc(ref m);
}
开发者ID:majkinetor,项目名称:FormsFramework,代码行数:15,代码来源:IPC.cs
示例12: SendString
private void SendString(IntPtr wnd)
{
string s = "hi2server" + char.MinValue;
IntPtr lpData = Marshal.StringToHGlobalAnsi(s);
COPYDATASTRUCT data = new COPYDATASTRUCT();
data.dwData = 0;
data.cbData = s.Length + 1;
data.lpData = lpData;
IntPtr lpStruct = Marshal.AllocHGlobal(Marshal.SizeOf(data));
Marshal.StructureToPtr(data, lpStruct, false);
SendMessage(wnd, WM_COPYDATA,this.Handle, lpStruct);
}
开发者ID:GroundZero,项目名称:Nameless,代码行数:15,代码来源:Form1.cs
示例13: DefWndProc
protected override void DefWndProc(ref System.Windows.Forms.Message m)
{
string token = "";
COPYDATASTRUCT mystr;
Type mytype = null;
//MessageBox.Show(m.Msg.ToString());
switch (m.Msg)
{
case WM_MESSAGE:
mystr = new COPYDATASTRUCT();
mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
token = mystr.bstrData;
eterm_bga.is_eterm_status = mystr.bstrData;
eterm_bga.ib_connect_status = false;
eterm_bga.ib_dataflag = false;
// MessageBox.Show(this, mystr.bstrData, mystr.bstrCategory);
break;
case WM_DATA:
mystr = new COPYDATASTRUCT();
mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
token = mystr.bstrData;
ShowData(token);
break;
case WM_CTX:
mystr = new COPYDATASTRUCT();
mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
token = mystr.bstrToken;
CreatingCtx((int)m.WParam, token);
break;
default:
base.DefWndProc(ref m);
if (eterm_bga.ib_connect_status)
{
eterm_bga.is_eterm_status = "Host system down";
eterm_bga.ib_connect_status = false;
eterm_bga.ib_dataflag = false;
}
break;
}
}
开发者ID:greatfly,项目名称:Eterm_CS,代码行数:47,代码来源:eterm_base.cs
示例14: DefWndProc
//接收传递的消息
protected override void DefWndProc(ref Message m)
{
switch (m.Msg)
{
case WM_COPYDATA:
COPYDATASTRUCT mystr = new COPYDATASTRUCT();
Type mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
receiveMsg = mystr.lpData;
displayMessage(receiveMsg);
break;
default:
base.DefWndProc(ref m);
break;
}
}
开发者ID:zhushengwen,项目名称:example-zhushengwen,代码行数:18,代码来源:FrmChat.cs
示例15: DecodeMessage
public static string DecodeMessage(ref Message message)
{
string messageText = string.Empty;
COPYDATASTRUCT cds = new COPYDATASTRUCT();
cds = (COPYDATASTRUCT)Marshal.PtrToStructure(message.LParam, typeof(COPYDATASTRUCT));
if (cds.cbData > 0)
{
byte[] data = new byte[cds.cbData];
Marshal.Copy(cds.lpData, data, 0, cds.cbData);
MemoryStream stream = new MemoryStream(data);
BinaryFormatter b = new BinaryFormatter();
messageText = (string)b.Deserialize(stream);
}
return messageText;
}
开发者ID:xwiz,项目名称:WixEdit,代码行数:17,代码来源:CopyDataMessenger.cs
示例16: WndProc
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_COPYDATA)
{
COPYDATASTRUCT data = new COPYDATASTRUCT();
data = (COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
if (data.dwData == (IntPtr)COPYDATAENTRY.COPYDATA_NPCLogger && data.cbData > 0)
{
char[] buffer = new char[data.cbData / 2];
Marshal.Copy(data.lpData, buffer, 0, data.cbData / 2);
string npcmessage = new string(buffer);
AppendNPCMessage(npcmessage);
}
}
base.WndProc(ref m);
}
开发者ID:chatchanunn,项目名称:SimpleROHook,代码行数:18,代码来源:NPCLogger.cs
示例17: SendMessage
public override byte[] SendMessage(byte[] aMessage)
{
var hwnd = FindWindow(cPageantWindowClass, cPageantWindowClass);
if (hwnd == IntPtr.Zero) {
throw new AgentNotRunningException();
}
var threadId = Thread.CurrentThread.ManagedThreadId;
var mapName = String.Format("{0}{1:x8}", cMapNamePrefix, threadId);
using (var mappedFile = MemoryMappedFile.CreateNew(mapName, 4096)) {
if (mappedFile.SafeMemoryMappedFileHandle.IsInvalid) {
throw new Exception("Invalid mapped file handle");
}
using (var stream = mappedFile.CreateViewStream()) {
stream.Write(aMessage, 0, aMessage.Length);
var copyData = new COPYDATASTRUCT();
if (IntPtr.Size == 4) {
copyData.dwData = new IntPtr(unchecked((int)AGENT_COPYDATA_ID));
} else {
copyData.dwData = new IntPtr(AGENT_COPYDATA_ID);
}
copyData.cbData = mapName.Length + 1;
copyData.lpData = Marshal.StringToCoTaskMemAnsi(mapName);
IntPtr copyDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(copyData));
Marshal.StructureToPtr(copyData, copyDataPtr, false);
var resultPtr =
SendMessage(hwnd, WM_COPYDATA, IntPtr.Zero, copyDataPtr);
Marshal.FreeHGlobal(copyData.lpData);
Marshal.FreeHGlobal(copyDataPtr);
if (resultPtr == IntPtr.Zero) {
throw new Exception("send message failed");
}
stream.Position = 0;
var parser = new BlobParser(stream);
var replyLength = parser.ReadInt();
stream.Position = 0;
var reply = new byte[replyLength + 4];
stream.Read(reply, 0, reply.Length);
return reply;
}
}
}
开发者ID:dlech,项目名称:SshAgentLib,代码行数:41,代码来源:PageantClient.cs
示例18: DefWndProc
protected override void DefWndProc( ref System.Windows.Forms.Message m )
{
switch ( m.Msg )
{
case Win32API.WM_COPYDATA:
COPYDATASTRUCT mystr = new COPYDATASTRUCT();
Type mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam( mytype );
String op = mystr.lpData;
switch ( op )
{
case SecuruStikMessageType.Show:
this.Visible = true;break;
case SecuruStikMessageType.Hiden:
this.Visible = false;break;
}
break;
default:
base.DefWndProc( ref m );
break;
}
}
开发者ID:lixiaoyi1108,项目名称:SecuruStik,代码行数:22,代码来源:SplashScreen.cs
示例19: Main
static void Main(string[] args)
{
Process current = Process.GetCurrentProcess();
var runningProcess = Process.GetProcessesByName(current.ProcessName).FirstOrDefault(p => p.Id != current.Id);
if (runningProcess == null)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new WindowsFormsApplication1.Form1(args));
}
else
{
var hwnd = runningProcess.MainWindowHandle;
SetForegroundWindow(hwnd);
var cd = new COPYDATASTRUCT();
for (int i = 0; i < args.Length; i++)
{
cd.lpData += args[i] + " ";
}
cd.cbData = cd.lpData.Length + 1;
SendMessage(hwnd, WM_COPYDATA, 101, ref cd);
}
}
开发者ID:rocbomb,项目名称:homework-03,代码行数:23,代码来源:Program.cs
示例20: Main
static void Main(string[] args) {
Process proc = Process.GetCurrentProcess();
// 多重起動時の処理
// NOTE: デバッガ上で起動した場合、通常起動とはプロセス名が違う。
// そのため、デバッガ上でテストする方法が今の所不明
if (Process.GetProcessesByName(proc.ProcessName).Length > 1) {
if (args.Length > 0) {
var prevHwnd = FindPrevProcess(proc);
var msg = args[0];
var cds = new COPYDATASTRUCT();
cds.dwData = IntPtr.Zero;
cds.lpData = msg;
cds.cbData = System.Text.Encoding.Default.GetBytes(msg).Length + 1;
SendMessage(prevHwnd, WM_COPYDATA, IntPtr.Zero, ref cds);
}
}
else {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0) Application.Run(new MainForm(args[0]));
else Application.Run(new MainForm());
}
}
开发者ID:cube-soft,项目名称:CubePdfViewer,代码行数:24,代码来源:Program.cs
注:本文中的COPYDATASTRUCT类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论