Invalid handle?


Several Windows Embedded CE API’s deal with handles: an application obtains a handle to an object than it typically checks if the handle is valid or not; unfortunately there are two values which means invalid handle: for example CreateFile returns INVALID_HANDLE_VALUE (which is defined as -1 or 0xFFFFFFFF) while CreateEvent returns NULL.

A mnemonic aid is the following: all the API’s that deal with files, storage and database (CreateFile, FindFirstChangeNotification, OpenStore, CeOpenDatabaseEx, …) return INVALID_HANDLE_VALUE while the other API’s return NULL.  

Some noticeable exceptions to this statement are:

  • CreateToolhelp32Snapshot
  • FindFirstDevice
  • CeFindFirstRegChange

which returns INVALID_HANDLE_VALUE.

Note that there is an error in Windows Embedded CE documentation about OpenDeviceKey: it is stated that the function returns INVALID_HANDLE_VALUE in case of error while it actually returns NULL.

Advertisements
This entry was posted in Windows Embedded CE and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s