I was looking into getting the device name today and was surprised by what I found. I already knew that the device name was in the registry as:
[HKEY_LOCAL_MACHINE\Ident]
    "Name"="<Some Name>"
    "Desc"="<Some description of the system>"
So it seemed obvious that to get the device name all I needed to do was to read the strings from the registry. I have already covered reading strings from the registry in Windows CE: Reading a String from the Registry so I won’t go into that here.
Then I decided to see how the System control panel applet gets the device name, which is where the surprise came in. The control panel applet doesn’t get the device name from the registry, instead it uses WinSock to get the name.  With WinSock it call gethostname().  I suppose that makes sense because this is actually presenting the network name of the device. My read of the code suggests that if WinSock support is not included in the OS, the name won’t be displayed at all. WinSock does actually use the same registry entry to get the device name, which is good.
Doing some searching, but not a thorough search, I found that if you are using Platform Builder there is a function available to get the device name. It is GetComputerName(), and is available in Public\Common\OAK\Inc\Portstub.h as an inline function. But you only get this function if you are using Platform Builder, so application developers are out of luck.
Copyright © 2009 – Bruce Eitman
All Rights Reserved