我现在要进行托管和非托管之间的通信
public enum ItemType
{
String,
Byte,
}
public class QueueItem
{
private ItemType type; private int itemId; private byte[] context; //private int contextLength;
public QueueItem(ItemType type,int id,byte[] context)
{
this.type = type;
this.itemId = id;
this.context = new byte[context.Length];
//this.contextLength = this.context.Length;
//Buffer.BlockCopy(context, 0, this.context, 0, context.Length);
//this.context = context;
//PackCommands();
}
//public int ContextLength
//{
// get
// {
// return this.contextLength;
// }
//}
public int ItemID
{
get
{
return itemId;
}
}
public byte[] Context
{
get
{
return context;
}
}
public ItemType Type
{
get
{
return type;
}
}
}
这是个元素类 [DllImport("coredll.dll")]
public static extern int SendMessage(System.IntPtr wnd, uint msg, UInt16 wparam, UInt16 lparam);
public virtual void EnQueue(QueueItem item)
{
IntPtr _formHandl;
if (_type == TransferType.ClientTransfer)
_formHandl = PublicLib.NativeApi.NativeMethod.FindWindow(null, Mantis);
else
_formHandl = PublicLib.NativeApi.NativeMethod.FindWindow(null, Client); _sendItem = System.Runtime.InteropServices.Marshal.AllocHGlobal(QueueItemTool.PackCommands(item.Context,item.Type).Length);
//在这以上都不用管,关键是下边这句话,总是过不去,我怀疑是ITEM的格式问题,不知道为什么
System.Runtime.InteropServices.Marshal.StructureToPtr(item.Context, _sendItem, true);
Microsoft.WindowsCE.Forms.Message msg = Microsoft.WindowsCE.Forms.Message.Create(
_formHandl,
WM_CUSTOMMSG,
_sendItem, _sendItem);
MessageWindow.PostMessage(ref msg);
}
public enum ItemType
{
String,
Byte,
}
public class QueueItem
{
private ItemType type; private int itemId; private byte[] context; //private int contextLength;
public QueueItem(ItemType type,int id,byte[] context)
{
this.type = type;
this.itemId = id;
this.context = new byte[context.Length];
//this.contextLength = this.context.Length;
//Buffer.BlockCopy(context, 0, this.context, 0, context.Length);
//this.context = context;
//PackCommands();
}
//public int ContextLength
//{
// get
// {
// return this.contextLength;
// }
//}
public int ItemID
{
get
{
return itemId;
}
}
public byte[] Context
{
get
{
return context;
}
}
public ItemType Type
{
get
{
return type;
}
}
}
这是个元素类 [DllImport("coredll.dll")]
public static extern int SendMessage(System.IntPtr wnd, uint msg, UInt16 wparam, UInt16 lparam);
public virtual void EnQueue(QueueItem item)
{
IntPtr _formHandl;
if (_type == TransferType.ClientTransfer)
_formHandl = PublicLib.NativeApi.NativeMethod.FindWindow(null, Mantis);
else
_formHandl = PublicLib.NativeApi.NativeMethod.FindWindow(null, Client); _sendItem = System.Runtime.InteropServices.Marshal.AllocHGlobal(QueueItemTool.PackCommands(item.Context,item.Type).Length);
//在这以上都不用管,关键是下边这句话,总是过不去,我怀疑是ITEM的格式问题,不知道为什么
System.Runtime.InteropServices.Marshal.StructureToPtr(item.Context, _sendItem, true);
Microsoft.WindowsCE.Forms.Message msg = Microsoft.WindowsCE.Forms.Message.Create(
_formHandl,
WM_CUSTOMMSG,
_sendItem, _sendItem);
MessageWindow.PostMessage(ref msg);
}
解决方案 »
- 小生刚学C#,人说C#应用不广,求高人指点
- 怎么获取按下键盘的信息,比如在计算器中。我按下键盘的1、2、3……可以知道按下对应的数字键。
- 趣味小问题,你有办法用循环声明 名为1、2、3、4、5、....1000的string类型的变量吗
- .Net 企业库 RAS加密app.config文件后 出现的问题
- 问一下如何使用C#,来清空剪切板?
- c# 如何获取数据库中,以上传的图片数量,和视屏数量,视频分钟,
- 急求暂时离开C#代码
- 如何从DSN中读取数据库连接信息?
- 100分求vs.net 2003,msdn 2003,4月的
- 如何操作Gif格式的图片?(急救)
- 请教一个Linq语句
- 高手给看看“object”并不包含“GetIdSet”的定义
IntPtr ptr = handle.Value;
System.Runtime.InteropServices.Marshal.StructureToPtr(item.Context, _sendItem, true);
如果你是想将item.Context从托管对象封送到非托管内存块那么把对象改为item.Context