Windows Phone 8.1 Driver Development--Registry Read/write

Source: Internet
Author: User

When you do Windows Phone driver development, you often need to deal with the registry, so as a mobile phone driver developer, it is necessary to understand the registry-related knowledge. I do not know about the registry at present, but also only about the knowledge that under the Windows Phone, the driver INF file does not provide the driver automatic installation program like the desktop Windows, under the Windows Phone, INF file is eventually parsed into registry information and added to the registry. We drive often save some hardware parameters in the registry, so in software programming, it will naturally involve the registry read and write update operations.


I am currently in touch screen driver, it involves the registry read and write operations. To facilitate later viewing, the registry is posted with the update UpdateRegistry () and the Read Readregistry () function code.


To update the registry:

NTSTATUS __DRV_REQUIRESIRQL (passive_level) updateregistry (__in wdfdevice fxdevice, __in punicode_str    ING subkeyname, __in punicode_string ValueName, __inout punicode_string Value) {NTSTATUS status;    NTSTATUS Regflushstatus;    Wdfkey Key = NULL;    Wdfkey subkey = NULL;    HANDLE Keyhandle;    Paged_code ();                                      Find FileName from registry key//Status = Wdfdeviceopenregistrykey (Fxdevice,                                      Plugplay_regkey_device, Standard_rights_all,    Wdf_no_object_attributes, &key); if (!    Nt_success (status)) goto exit;    Status = Wdfregistryopenkey (Key, SubkeyName, Key_read, Wdf_no_object_attributes, &subkey); if (!    Nt_success (status)) goto exit;    Status = Wdfregistryassignunicodestring (subkey, ValueName, Value); if (!    Nt_success (status)) goto exit; Flush the key foR immediate Effect Keyhandle = Wdfregistrywdmgethandle (subkey);    if (NULL! = keyhandle) {regflushstatus = Zwflushkey (Keyhandle);    }exit:if (subkey! = NULL) Wdfregistryclose (subkey);    if (Key! = NULL) wdfregistryclose (key); return status;}


Read the registry:

NTSTATUS __DRV_REQUIRESIRQL (passive_level) readregistry (__in wdfdevice fxdevice, __in punicode_string Subkey    Name, __in punicode_string ValueName, __inout punicode_string Value) {NTSTATUS Status;    Wdfkey Key = NULL;    Wdfkey subkey = NULL;    Paged_code ();                                       Find FileName from registry key//Status = Wdfdeviceopenregistrykey (Fxdevice, Plugplay_regkey_device, Key_read, WD    F_no_object_attributes, &key); if (!    Nt_success (Status)) goto exit;    Status = Wdfregistryopenkey (Key, SubkeyName, Key_read, Wdf_no_object_attributes, &subkey); if (!    Nt_success (Status)) goto exit;    Get String//Status = Wdfregistryqueryunicodestring (subkey, ValueName, NULL, Value); if (! Nt_success (Status)) Goto EXIT;EXIT:IF (subkey! = NULL) Wdfregistryclose (SuBkey);    if (Key! = NULL) wdfregistryclose (key); return Status;}



function use case

INF file:

;; Touchdetectiondriver.inf, ..... [TouchDetectionDriver_Device.NT.HW] AddReg = filterinst.nt.hw.addreg[filterinst.nt.hw.addreg]hkr,%qttouchregpath%, "Touchcontrollerid", 0x00000002, "FF "hkr,%qttouchregpath%," Forcecontrollerprobe ", 0x00000002," 1 "... [Strings] Qttouchregpath = "Configuration File" ...
The INF file will eventually be parsed into registry information and added to the system registry. As you can see, there are two entry under the sub-key configuration file directory, respectively, Touchcontrollerid and Forcecontrollerprobe, with the key values "FF" and "1" respectively.


Driver files:

NTSTATUS registrytest (Wdfdevice fxdevice) {NTSTATUS status = status_success;    Unicode_string Strcontrollerid;    ULONG Touchcontrollerid = 0;    WCHAR Szidbuffer[3] = {0};    Unicode_string Strforceprobe;    ULONG forcecontrollerprobe = 0;    WCHAR Szprobebuffer[3] = {0};    Declare_const_unicode_string (SubkeyName, L "Configuration File");    Declare_const_unicode_string (Keytouchcontrollerid, L "Touchcontrollerid");    Declare_const_unicode_string (Keyforcecontrollerprobeid, L "Forcecontrollerprobe");    Read Touchcontrollerid rtlinitemptyunicodestring (&strcontrollerid, Szidbuffer, sizeof (Szidbuffer)); Readregistry (Fxdevice, (punicode_string) &subkeyname, (punicode_string) &KeyTouchControllerID,&    Strcontrollerid);    Rtlunicodestringtointeger (&strcontrollerid, ten, (Pulong) &touchcontrollerid);    Tddlog ("TDD:ControllerIDFromRegistry:ControllerID Registry Value is%d\n", Touchcontrollerid); Read forcecontrollerprobe rtlinitemptyunicodestring (&strfoRceprobe, Szprobebuffer, sizeof (Szprobebuffer)); Readregistry (Fxdevice, (punicode_string) &subkeyname, (punicode_string) &keyforcecontrollerprobeid, &    Strforceprobe);    Rtlunicodestringtointeger (&strforceprobe, ten, (Pulong) &forcecontrollerprobe);    Tddlog ("TDD:ControllerIDFromRegistry:Force controller probe Register Value is%d\n", forcecontrollerprobe);    Update Touchcontrollerid rtlintegertounicodestring (1, ten, &strcontrollerid); UpdateRegistry (Fxdevice, (punicode_string) &subkeyname, (punicode_string) &keytouchcontrollerid, &    Strcontrollerid);    Update Forcecontrollerprobe rtlintegertounicodestring (0, ten, &strforceprobe); UpdateRegistry (Fxdevice, (punicode_string) &subkeyname, (punicode_string) &keyforcecontrollerprobeid, &    Strforceprobe); return status;}




Windows Phone 8.1 Driver Development--Registry Read/write

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.