Code in VB for getting a Device Unique ID (Product ID) please

  • Thread starter Thread starter NET CF Questions
  • Start date Start date
N

NET CF Questions

We're looking for a sample code for getting a Device Unique ID
(Product ID) in VB.

VB, VS 2005, .Net cf 2.0 sp2

The one we have from the manufacturer is in C++

////////////////////////////////////////////////////////////////
HWND hDeviceId = GetDlgItem(hWnd, IDC_DEVICEID);
PDEVICE_ID pDeviceID = NULL;
TCHAR outBuf[512], szProductID[100], stringBuffer[100];
BYTE szBuff[255];
DWORD bytesReturned;
char platformID[64];
pDeviceID = (PDEVICE_ID)outBuf;
pDeviceID->dwSize = sizeof(outBuf);
if (KernelIoControl(IOCTL_HAL_GET_DEVICEID, NULL, 0, outBuf,
sizeof(outBuf), &bytesReturned))
{
// Platform ID
memcpy((PBYTE)platformID, (PBYTE)pDeviceID + pDeviceID-
dwPlatformIDOffset, pDeviceID->dwPlatformIDBytes);
// Device ID for WinCE version
memcpy((PBYTE)stringBuffer, (PBYTE)pDeviceID + pDeviceID-
dwPresetIDOffset, pDeviceID->dwPresetIDBytes);
swprintf(szProductID, _T("%s"), stringBuffer);
// Device ID for Mobile version
memcpy((PBYTE) szBuff, (PBYTE)pDeviceID + pDeviceID->dwPresetIDOffset,
pDeviceID->dwPresetIDBytes);
swprintf(szProductID, TEXT("%X%X%X%X%X%X%X%X"),
szBuff [0], szBuff [1], szBuff [2], szBuff [3], szBuff [4], szBuff
[5], szBuff [6], szBuff [7]);
}
/////////////////////////////////////////////////////////
The code will have platformID holds Platform ID, and deviceID holds
Device ID.
 
Did you check to see if the C++ code returned the same value? I'm going to
make a stretch guess here and assume that you copied the MSDN code and ran
it, but really don't understand at all what it's doing. You need to fully
understand what its doing so you can determine if it's actually running
properly and doing the same thing that the C sample your OEM provided is
doing.

If it is indeed running properly *and* is doing what their C sample is doing
and you're still getting something different, then that will tell you that
the code they gave you does not product the text you're after and you need
to ask them how to get that text.

You currently have all of the information you need to solve this. I have
some strong guesses on the answers to all of these, but just telling you
isn't going to facilitate you learning or becomming a better programmer.
Having to hunt it down yourself will.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
but just telling you
isn't going to facilitate you learning or becomming a better programmer.
Having to hunt it down yourself will.

Thank you for your response.
I'm actually not a developer or programmer, nor do I aspire to be one,
it's just not how my brain works.
(Hence the horrifically n00bish and inappropriately phrased questions
from me..)

I'm troubleshooting and collecting information for the development
team who has very little experience with mobile devices and who are 2
months behind on a development project thanks to a alarmingly
irresponsible and incompetent Mobile Device development consultant.
They are working up to 18 hours a day to meet the deadline and provide
the best application possible and I'm trying to get them answers on
the issues that are important to, but not core development issues so
their time can be spent developing.

While they'd like nothing better than to take the time to learn the
ins and outs as well as possible, currently there's a business
deadline to be met, responsibilities to clients, and very little time
in which to do it thanks to the "pro" and his lack of understanding
of time frames and, well, business as well I guess.

I will most certainly ask the device manufacturer.
The question came up over the long holiday while they weren't in, so I
gave asking it here a shot.
 
Looking at the sample C++ code and the MSDN article, on the surface they
appear to be doing the same thing - calling a Kernel IOCTL to get data. I
didn't verify the correctness of setting buffers, etc, or that constants are
properly defined, but the general principle seems to be correct.

That said, we don't know what your device displays when you press F9 -
that's very device dependent. My bet is that it's not calling the IOCTL
though - it's probably using the same logic as the default "system info"
control panel applet, which doesn't do this. It simply gets the device name
from the registry, which is certainly not unique - it's often the same for
the entire device line (or at least the CE image burned into them). Bottom
line, though, is that only the OEM knows.

It bothers me to hear that you've had a bad experience with a mobile
consultant and I empathize with your plight. It doesn't surprise me though.
A lot of companies and contractors are happy to say they can do device
development because they have some level of managed code experience and
somehow think that it just magically translates to device development.

Obviously it's way too late in your case, but everyone should be very
careful to be sure that their consultants are well vetted for this kind of
work. Make sure they have done other mobile and embedded projects and get
(and contact) customer references to make sure they really did do the work
they claim and that they didn't screw it up. Mobile development is *not* the
same as desktop development, no matter what any marketing or sales person
tries to tell you. We've spent a lot of time fixing and undoing what other
people have done.

There are some very qualified consultants out there - I can name half a
dozen offhand - but I've found that there are far more claiming to do mobile
and device development that actually don't know their jack &*^% about it.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
Back
Top