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

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

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