我定義了一個結構體,如下
public struct MsgInfo
{
public byte[] buffer;//不定長
public int length;
public MsgInfo(byte[] buffers, int lengths)
{
buffer = buffers;
length = lengths;
}
}
使用了PostThreadMessage向指定id執行緒發送過去 ,如下
[DllImport("user32.dll", EntryPoint = "PostThreadMessage")]
private static extern int PostThreadMessage(int threadId, uint Msg, ref MsgInfo wParam, uint IParam);
public void sendMessage(byte[] ReBuffer, int length)
{
MsgInfo info = new MsgInfo(buffer, length);
PostThreadMessage(main.abc.GetThreadId(), 0x4002, ref info, 0);
}
我新建了一個執行緒去接受操作該資料,資料多點發送,我想只在這個執行緒中去操作資料,GetMessage要怎么處理才能決議到wParam的MsgInfo結構體中的資料?因為是單獨類來操作,沒有表單,不能通過重寫表單訊息處理函式DefWndProc來操作。
這是接收的執行緒函式
[DllImport("kernel32.dll")]
private static extern int GetCurrentThreadId();
[DllImport("User32.dll", EntryPoint = "GetMessage")]
private static extern int GetMessage(ref tagMsg lpMsg, uint hwnd, uint wMsgFilterMin, uint wMsgFilterMax);
public struct tagMsg
{
public int hwnd;
public uint message;
public MsgInfo wParam;//public uint wParam
public uint lParam;
public uint time;
public Point pt;
}
private void Loop_Thread()
{
ThreadId = GetCurrentThreadId();
tagMsg msg = new tagMsg();
while (GetMessage(ref msg, 1, 0, 0) > 0)//獲取訊息 這里會報錯 但PostThreadMessage時不會 求大佬指點應該怎么操作
{
switch(msg.message)
{
case 0x4002:
byte[] ss = msg.wParam.buffer;
break;
default:
break;
}
}
}
請大佬指導指導
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/255016.html
標籤:C#
