473,660 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calls to SendMessage api

Hi,

My application has a lot of threads which at some point call SendMessage api
passing it the handle of the gui window. The calls r a lot. My question is
that should I call the SendMessage api by protecting it in a critical
section, or the SendMessage api itself handles this kind of situation where
a lot of threads in the same process r calling it.

Regards,

-ab.
Oct 15 '06 #1
4 2127
Abubakar wrote:
Hi,

My application has a lot of threads which at some point call SendMessage api
passing it the handle of the gui window. The calls r a lot. My question is
that should I call the SendMessage api by protecting it in a critical
section, or the SendMessage api itself handles this kind of situation where
a lot of threads in the same process r calling it.

Regards,

-ab.

ab:

The good thing about SendMessage() is that it does not return until the
action in the other thread is complete. So you do not have to worry
about thread safety.

The bad thing about SendMessage() is that it does not return until the
action in the other thread is complete. So you can block yourself if you
are not careful. Many people say you should never use SendMessage() for
inter-thread communication. I disagree, but you DO need to be careful.

David Wilkinson
Oct 15 '06 #2
Ok, can u tell me what does the following means:

"The system only does marshalling for system messages (those in the range 0
to (WM_USER-1)). To send other messages (those >= WM_USER) to another
process, you must do custom marshalling."

This is from msdn documentation. Here I dont understand the meaning of "you
must do custom marshalling". The messages that so many of my threads r
sending to the gui handle r all declared greater than WM_USER and I'm not
doing anything extra than just passing those messages to the sendmessage
api.

regards,

-ab.

"David Wilkinson" <no******@effis ols.comwrote in message
news:OX******** ******@TK2MSFTN GP05.phx.gbl...
Abubakar wrote:
>Hi,

My application has a lot of threads which at some point call SendMessage
api passing it the handle of the gui window. The calls r a lot. My
question is that should I call the SendMessage api by protecting it in a
critical section, or the SendMessage api itself handles this kind of
situation where a lot of threads in the same process r calling it.

Regards,

-ab.


ab:

The good thing about SendMessage() is that it does not return until the
action in the other thread is complete. So you do not have to worry about
thread safety.

The bad thing about SendMessage() is that it does not return until the
action in the other thread is complete. So you can block yourself if you
are not careful. Many people say you should never use SendMessage() for
inter-thread communication. I disagree, but you DO need to be careful.

David Wilkinson

Oct 15 '06 #3
"Abubakar" <em**********@y ahoo.comwrote in message
news:Of******** ******@TK2MSFTN GP05.phx.gbl...
Ok, can u tell me what does the following means:

"The system only does marshalling for system messages (those in the range
0 to (WM_USER-1)). To send other messages (those >= WM_USER) to another
process, you must do custom marshalling."
The issue has to do with pointers.

The "w" and "l" parameters of a message will be the same on the sending and
receiving sides. Sometimes, one of those parameters which is defined to be a
simple unsigned quantity is used to pass an address as in the case of
WM_SETTEXT.

Because applications do not share their address spaces, a pointer in one
application is meaningless to another. So if Windows didn't handle it as a
special case, you couldn't send a WM_SETTEXT message across a process
boundary.

What the documentation is (almost <g>) telling you here is when you send a
message with a pointer in one of the messages with a value less than
WM_USER, that windows will pass the data as well as modifying the pointer on
the receiving side so that the receiver can access it.

Of course, in order for Windows to do this it needs to know which parameters
are pointers in which messages. Those messages are roughly the ones which
were defined in Windows 3.1.

For your own message, or many of the common controls introduced after 16 bit
Windows, you need to marshal the data.

Regards,
Will

Oct 15 '06 #4
Thanks.

-ab.

"William DePalo [MVP VC++]" <wi***********@ mvps.orgwrote in message
news:eU******** ******@TK2MSFTN GP05.phx.gbl...
"Abubakar" <em**********@y ahoo.comwrote in message
news:Of******** ******@TK2MSFTN GP05.phx.gbl...
>Ok, can u tell me what does the following means:

"The system only does marshalling for system messages (those in the range
0 to (WM_USER-1)). To send other messages (those >= WM_USER) to another
process, you must do custom marshalling."

The issue has to do with pointers.

The "w" and "l" parameters of a message will be the same on the sending
and receiving sides. Sometimes, one of those parameters which is defined
to be a simple unsigned quantity is used to pass an address as in the case
of WM_SETTEXT.

Because applications do not share their address spaces, a pointer in one
application is meaningless to another. So if Windows didn't handle it as a
special case, you couldn't send a WM_SETTEXT message across a process
boundary.

What the documentation is (almost <g>) telling you here is when you send a
message with a pointer in one of the messages with a value less than
WM_USER, that windows will pass the data as well as modifying the pointer
on the receiving side so that the receiver can access it.

Of course, in order for Windows to do this it needs to know which
parameters are pointers in which messages. Those messages are roughly the
ones which were defined in Windows 3.1.

For your own message, or many of the common controls introduced after 16
bit Windows, you need to marshal the data.

Regards,
Will

Oct 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1456
by: nnb295 | last post by:
Hi, is it with the .Net-Class-library possible to send a message with the same effect like the API-Call "SendMessage" to another application window or control without Windows-API-Calls. Thanks nnb295
2
7049
by: 2G | last post by:
Hi everybody I think i'm doing something wrong . :) When I install a new font, all my programs (like photoshop) that are running don't respond anymore for like 2 min, after that I can use the font whitout restarting the applications but I can not delete the font untill i reboot my pc (i tried killing all processes but that didn't work). If anyone would take a look , I do the following :
3
2991
by: Peter van der Veen | last post by:
Hi In my prgragm i use an API call to open the combobox when it get the focus. The code i use is this Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam
3
2118
by: Steve | last post by:
Hi all, Could someone provide a link to working code examples for implementing these Sendmessage API calls in VB.NET ?? EM_GETLINECOUNT EM_GETLINE EM_LINELENGTH EM_LINEINDEX
18
6557
by: Lars Netzel | last post by:
Hello! Thanx to this newgroup I have finally, with the help of you guys, gotten this to work halfway.. but the final action is still not working, clicking the "Button2" thru SendMessage(). Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
3
5084
by: Max M. Power | last post by:
When I use the SendMessage API I can sucessfully send and receive a user defined message. When I use the PostMessage API I can NOT sucessfully send and receive the same user defined message. I've got a C# class library project with two classes: Class 1 is derives from : System.Windows.Forms.Form and overrides the base WndProc method for the purpose of receiving and handeling user defined messages:
2
1472
by: Abubakar | last post by:
Hi, in my application, different threads send notifications to GUI thread through sendmessage api. They have special integer numbers inside the wParam arg of sendmessage which the gui thread uses to display messages in the textboxes etc. My question is that in case the threads send messages very fast (which does NOT always happen in my app), faster than the gui thread is processing them, are the messages qued automatically (btw the gui...
7
2851
by: Shak | last post by:
Hi all, I'm trying to write a thread-safe async method to send a message of the form (type)(contents). My model is as follows: private void SendMessage(int type, string message) { //lets send the messagetype via async NetworkStream ns = client.GetStream(); //assume client globally accessible
22
9238
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. I'm sure the problem is the way i'm using the sendmessage API, the return string and the lParam return 0....is anybody have a clue? any sendmessage api expert here? public static extern Int32 FindWindow(String lpClassName,String
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.