Home > Net >  C # the PostThreadMessage send receive structure USES the GetMessage
C # the PostThreadMessage send receive structure USES the GetMessage

Time:02-01

I define a structure, the following
 public struct MsgInfo 
{

Public byte [] buffer;//u
Public int length;
Public MsgInfo (byte [] buffers, int lengths)
{
Buffer=buffers;
Length=lengths;
}
}

Used to specify PostThreadMessage id thread to send in the past, the following
 
[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 (), 0 x4002, ref info, 0).
}

I opened a thread to manipulate the data, data points to send, I think only to manipulate the data in this thread, GetMessage how to deal with to parse the wParam MsgInfo structure in the data? Because it is a separate class to operate, no form, not by rewriting forms DefWndProc message processing function to operate,
This is receiving thread function
 [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) & gt; 0)//get messages here complains but not when PostThreadMessage bosses should show how to operate the
{
The switch (MSG) message)
{
Case 0 x4002:
Byte [] ss=MSG. WParam. Buffer;
break;
Default:
break;
}

}

}
please bosses guidance
  •  Tags:  
  • C#
  • Related