Home > Net >  Interprocess communication, WM_COPYDATA, why SendMessage are returns 0 after sending?
Interprocess communication, WM_COPYDATA, why SendMessage are returns 0 after sending?

Time:09-22

Fellow teachers, ask a problem of the communication thread (c #, and between the WM_COPYDATA way, can already normal send and receive data)

1, why called SendMessage sent are the returns 0, are all failed! But the official document description: (If the identifiers application the processes this message, it should return TRUE; Otherwise, it should return FALSE.)

2, send SendMessage function is blocking way, close the receiving process again to send, also didn't see stuck phenomenon (such as didn't see transmitter reply situation)? (Sends the specified message to a window or Windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.)

3, the receiver is through what way to tell the sender "I have normal take data?" Read the lParam?


In a word, software that want to know: the success of the sender to send data


Supplement: try to use c + + console to send, also returns 0 (the other party has received data)

CodePudding user response:

Marshal. GetLastWin32Error ();

Specific error code can see https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes
Such as 1400 errors for Invalid Handle,

If you control the receiver, also can return to a particular code 1,


BTW, using Windows messages do extensibility of communication between processes is very poor, now it is not recommended to do,

CodePudding user response:

reference 1st floor github_36000833 response:
Marshal. GetLastWin32Error ();

Specific error code can see https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes
Such as 1400 errors for Invalid Handle,

If you control the receiver, also can return to a particular code 1,


BTW, using Windows messages do extensibility of communication between processes is very poor, don't suggest to do now,



If you control the receiver, also can return to a particular code 1,????? How to understand

Recommended use Shared memory way?

CodePudding user response:

Q: if you control the receiver, can also return a specific code 1,????? How to understand
A: SendMessage returns an LRESULT, 32-bit application is an int, what do you want to return can actually,


Q: ?
A: depends on what you need, such as
The information interaction, a named pipe is best;
One-way large file data, memory mapping file;
Simple notification, naming the simplest signal;
Want to support Linux version at the same time, with the socket,

CodePudding user response:

SendMessage as the communication has some limitations:

1, need to have a message loop,
2, SendMessage confined to the Session, that is, not desktop applications and services program Session border SendMessage communications,
3, low permissions program, can't to access high program (for example, then began to ascend with UAC program) message,
4, it is more easily from other programs can be inspired by SendMessage/fraud,

CodePudding user response:

The
reference 3 floor github_36000833 response:
Q: if you control the receiver, can also return a specific code 1,????? How to understand
A: SendMessage returns an LRESULT, 32-bit application is an int, what do you want to return can actually,


Q: ?
A: depends on what you need, such as
The information interaction, a named pipe is best;
One-way large file data, memory mapping file;
Simple notification, naming the simplest signal;
Want to support Linux version at the same time, use socket,




SendMessage message received within DefWndProc, VOID, don't know is which steps do the return, or where do return,


Protected override void DefWndProc (ref Message m)
{
The switch (m.M sg)
{
Case ImportFromDLL. WM_COPYDATA:

ImportFromDLL. COPYDATASTRUCT cdata=https://bbs.csdn.net/topics/new ImportFromDLL. COPYDATASTRUCT ();
Type what=cdata. GetType ();
Cdata=https://bbs.csdn.net/topics/(ImportFromDLL COPYDATASTRUCT) m.G etLParam (buy);

//first line insert data way
//dwData value
TextBox_RiZ. Text=textBox_RiZ. Text. Insert (0, DateTime. Now. ToLongTimeString (), ToString () + "& gt;>>>>> & gt;" + Environment. NewLine);
TextBox_RiZ. Text=textBox_RiZ. Text. Insert (0, "dwData=" https://bbs.csdn.net/topics/+ cdata. DwData + Environment. The NewLine);
TextBox_RiZ. Text=textBox_RiZ. Text. Insert (0, "cbData=" https://bbs.csdn.net/topics/+ cdata. CbData + Environment. The NewLine);
TextBox_RiZ. Text=textBox_RiZ. Text. Insert (0, "lpData=" https://bbs.csdn.net/topics/+ cdata. LpData + Environment. The NewLine);


break;
//default:
//base. DefWndProc (ref m);
//break;
}
Base. DefWndProc (ref m);
}

CodePudding user response:

reference 5 floor ygb2015 reply:
...
SendMessage message received within DefWndProc, VOID, don't know is which steps do the return, or where do return,


Protected override void DefWndProc (ref Message m)
{
.
}


M . The Result =(IntPtr) 1;

  •  Tags:  
  • C#