1. David Canicoba
  2. PowerBuilder
  3. Saturday, 23 September 2017 15:52 PM UTC

Hi Greetings I would like to know how to use GetRawInputDeviceList and GetRawInputDeviceInfo APIs in PowerBuilder.

Roland Smith Accepted Answer Pending Moderation
  1. Sunday, 24 September 2017 19:36 PM UTC
  2. PowerBuilder
  3. # 1

Take a look at the example code here:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms645598(v=vs.85).aspx

You have to call the function once passing NULL (zero) in the first argument to find out how many there are. Then call it again passing it an array of structures. If the first call returns 10, then the array needs to have 10 occurrences prior to the second call. You'll need two external definitions of the function, one where the first argument is ulong and the second where it is the structure.

Comment
  1. Roland Smith
  2. Sunday, 24 September 2017 19:39 PM UTC
The free function doesn't need to be replicated. The malloc would be replaced by code that would force the corrent number of occurrences into the array. Just set a value into the last occurrence.

  1. Helpful
  1. yakov werde
  2. Monday, 4 November 2019 21:14 PM UTC
Hi Roland,



I'm waking up this discussion because I have a requirement to distinguish whether input is coming from the keyboard or a usb bar code scanner. Windows doesn't provide this insight to the Key event but an App can get it from the RawInputDeviceApi



I wondering if you have some insight into this HID (human interface device) API



This article has a c# example https://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard



Based on this MS definition:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputdevice

I created this structure

global type rawinputdevice from structure

uint usUsagePage

uint usUsage

ulong dwFlags

ulong hwndTarget

end type



To get started : Based on your suggestion above I added these two external function definitions



//Calling this function causes a system error -- wrong type for param 1 ??

function UINT GetRawInputDeviceList_size( long usize , ref UINT puiNumDevices, ref UINT cbSize) library 'user32.dll'



//Calling this function returns -1 ??

function UINT GetRawInputDeviceList( ref RAWINPUTDEVICE pRawInputDevices [ ] , ref UINT puiNumDevices, ref UINT cbSize) library 'user32.dll'



Here's the PB code (button click)

RAWINPUTDEVICE str_RawInputDevices_null ,str_RawInputDevices [ ]

UINT lui_NumDevices, lui_cbSize

int rc

//setnull (str_RAWINPUTDEVICEs_null) // compiler won't allow this

//long lsize

//setnull(lsize)

//GetRawInputDeviceList( lsize , lui_NumDevices, lui_cbSize) //<<causes system error

rc = GetRawInputDeviceList( str_RawInputDevices , lui_NumDevices, lui_cbSize)



Suggestion?



Thanks



Yakov

yakov.werde@iongroup.com
  1. Helpful
  1. Roland Smith
  2. Monday, 4 November 2019 21:54 PM UTC
I've never actually used those functions. I based my comments off what I got from the Microsoft documentation.



Check your data types here:

https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types?redirectedfrom=MSDN



Handles (HWND for example) should be Longptr so that it will work in 64bit.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.