Get the device ID in Windows Embedded

Source: Internet
Author: User
      This document describes how to obtain the device ID under wince, including the definition, acquisition, and cache of the device ID in wince.

      It is not difficult to obtain the device ID under wince. You only need to simply call kerneliocontrol. however, whether the device ID can be obtained and the type of the obtained ID is related to the implementation of the driver layer. the implementation of the device ID varies on different platforms. For example, in the l1_1404 Development Board of sharp, the device ID is located in platform. c. however, this article does not focus on how to set or compile the device ID, but only obtains the device ID through function calls.

      First, let's take a look at the definition of the device ID in wince:

  
  
  1. TypedefStruct_ Device_id {
  2. DWORD dwsize;
  3. DWORD dwpresetidoffset;
  4. DWORD dwpresetidbytes;
  5. DWORD dwplatformidoffset;
  6. DWORD dwplatformidbytes;
  7. } Device_id, * pdevice_id;

The structure is clear, and we only need to pay attention to the two fields: dwplatformidoffset and dwplatformidbytes.

Now assume that we have a platform whose device ID is a string: "mydeviceid", we can use the following simple example to obtain the device ID:

  
  
  1. CharSzbuf [max_path] = {0 };
  2. Device_id devid = {0 };
  3. Getdeviceid ((Byte*) Szbuf, max_path, & devid );
  4. CharSzdeviceid [max_path] = {0 };
  5. Strcpy (szdeviceid, szbuf + devid. dwplatformidoffset );

The string stored in szdeviceid is "mydeviceid ".

CodeGetdeviceid in is a self-written function to obtain the ID. The Code is as follows:

 
 
  1. DWORDGetdeviceid (Byte* Poutbuf,DWORDDwbufsize, device_id * pdeviceid)
  2. {
  3. DWORDDwread = 0;
  4. If(Kerneliocontrol (ioctl_hal_get_deviceid, null, 0, poutbuf, dwbufsize, & dwread) = false)
  5. {
  6. Return0;
  7. }
  8. Pdeviceid = (pdevice_id) poutbuf;
  9. ReturnDwread;
  10. }

Poutbuf is the input storage buffer, dwbufsize is the buffer size, pdeviceid is to accept the structure information of the device ID, the return value of the function is the number of bytes read, when the value is 0, probably because the device ID of function reading fails. the call method is simple. See the example above.

The ioctl_hal_get_deviceid in the Code is a macro defined in wince and focuses on obtaining the device ID. The macro is defined as follows:

 
  
  
  1. # Define ioctl_hal_get_deviceid ctl_code (file_device_hal, 21, method_buffered, file_any_access) 

The header file pkfuncs. h must be included to make the code work normally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.