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

  • Microsoft® Office 365 is a top choice for enterprises that want a cloud-based suite of productivity/ collaboration applications. With Office 365, you get access to Microsoft™ Office solutions practically anytime, anywhere, on virtually any device. It's a great option for current Microsoft users who can now build on their experience with Microsoft™ solutions while enjoying the flexibility of a cloud-based delivery. But even organizations with no previous investment in Microsoft will find that …

  • You've managed to piece together the "DREAM TEAM." Your tech staff works like a well-oiled machine, keeping your company humming and thriving. And then it happens: dissension. For whatever reason, your employees have grown unhappy and you find out they're searching for new employment or losing productivity. What did you do wrong? Did you hire the wrong people? Did your company push them away? Or is it a combination of numerous factors? Read this white paper to learn how to build an environment that fosters …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date