Hottest Forum Q&A on CodeGuru for the week of April 25th, 2004


Lots of hot topics are covered in the Discussion Forums on CodeGuru. If you missed the forums this week, you missed some interesting ways to solve a problem. Some of the hot topics this week include:

What is the usage of WM_NULL? (top)  


Alex Rest found the WM_NULL message and was curious where somebody would need to use that.

I have found a strange Windows message.
It is described in MSDN so:

The WM_NULL message performs no operation. An application sends
the WM_NULL message if it wants to post a message that the recipient
window will ignore.

I propose a competition for the the best idea how to use it.

This message really isn't strange at all. It can be used to verify whether or not an application is still responding. A famous window that does that is the Windows Task Manager by using SendMessageTimeout with WM_NULL. There are a few more methods were you have to use WM_NULL. JohnCz described them very well:

"WM_NULL also is used to filter messages in the WH_GETMESSAGE hook. Returning 0 from a hook does not prevent you from processing a message. Replacing a message with WM_NULL will filter the message properly."

Another use is an ActiveX control when you decide that it has a toolbar and tooltips. Normally, an application message pump calls PreTranslateMessage; because the ActiveX control does not have one, a message hook can call PreTranslateMessage and, if handled, replace the original message with WM_NULL.

Does a Machine ID for copy protection purposes exist? (top)  


Jim1981 has asked an intersting question. He needs to get a unique ID from the system, so that saved files from his application can't be opened on an another system.

Is there something like a unique machine ID that I can retrieve
so I can save a file and, when opened, know whether it was saved on
the same machine?

I don't want people using my saved files on any other machine apart
from the one on which it was saved on originally.

What is the best thing to grab that is unique to each machine?

First of all, you should know that nothing is guaranteed. Several hardware components contain a unique ID, but be advised that the components can be removed and implemented on another system. Another disadvantage is that when the customer's hardware crashes, he won't be able to open the saved files anymore. If you still want to use the unique ID, here are a few components that contain a unique ID and can be used for that purpose.

  • Serial number of the primary hard disk.
    Use GetVolumeInformation(); to retrive the information.
  • MAC address of the network card.
  • Serial number of the CPU
    Use GetSystemInfo to retrive the information.
  • Write to the Registry.

The best idea would be to use a combination of the above described methods. Also, take a look at the following articles:

Is there any range for WM_XXX messages that I could use without having any troubles with the Windows message handlers? (top)  


Zaph-0 wants to know whether there is any certain range to define WM_XXX messages for his own purposes.

Is there a certain range where I can define my WM_xxx messages
without causing any problems to Windows message handlers?

How about > 1000000?

In general, you can use both 'WM_USER' or 'WM_APP' for user-defined messages. However, you rather should use 'WM_APP' as a base for your user-defined messages because it provides fewer problems. Windows itself uses the range 'WM_USER + x' for several messages; therefore, you can run into conflict problems pretty easily. Besides that, take a look at the following MSDN entry: WM_USER Notification

How can I validate a auto_ptr? (top)  


kvpreeth is using a auto_ptr, but unfortunately, he doesn't know how to validate it. Do you?

I've a basic question regarding auto_ptr.

Assume this:

auto_ptr<T> pt( new T(1) );

Now, how do I validate pt before using pt.get()? In other words,
how can I make sure that pt has been allocated?

Is there any way to validate pt? I am using this for the first time.

Well, you answered your own question. The 'get' function will return 0 in case of a failure and 'new' is supposed to throw a 'bad_alloc' exception in case of a failure. Also, take a look at the following article: Using auto_ptr Effectively

About the Author

Sonu Kapoor

Sonu Kapoor is an ASP.NET MVP and MCAD. He is the owner of the popular .net website DotNetSlackers publishs the latest .net news and articles - it contains forums and blogs as well. His blog can be seen at:


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds