Skip to content

Update nf-winuser-getrawinputdevicelist.md #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions sdk-api-src/content/winuser/nf-winuser-getrawinputdevicelist.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,25 @@ To get more detailed information about the attached devices, call <a href="/wind
The following sample code shows a typical call to <b>GetRawInputDeviceList</b>:


```
UINT nDevices;
```cpp
UINT nDevices, nStored, i;
PRAWINPUTDEVICELIST pRawInputDeviceList;
if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { Error();}
if ((pRawInputDeviceList = malloc(sizeof(RAWINPUTDEVICELIST) * nDevices)) == NULL) {Error();}
if (GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)) == (<dtype rid="UINT"/>)-1) {Error();}
// do the job...
if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { Error(); }

// The list of devices can change between calls to GetRawInputDeviceList,
// so call it again if the function returns ERROR_INSUFFICIENT_BUFFER
do
{
if ((pRawInputDeviceList = realloc(sizeof(RAWINPUTDEVICELIST) * nDevices)) == NULL) { Error(); }
nStored = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST));
} while (nStored == (UINT)-1) && GetLastError() == ERROR_INSUFFICIENT_BUFFER);

if (nStored == (UINT)-1) { Error(); }

for (i = 0; i < nStored; ++i)
{
// do the job with each pRawInputDeviceList[i] element...
}

// after the job, free the RAWINPUTDEVICELIST
free(pRawInputDeviceList);
Expand Down