Advertisement
Guest User

Untitled

a guest
Jul 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 11.20 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2. Imports HIDs.Joysticks
  3.  
  4. ''' <summary>
  5. ''' Native API Functions for Joysticks
  6. ''' </summary>
  7. Partial Class NativeMethods 'joystick
  8.  
  9.     ''' <summary>
  10.     ''' The joyConfigChanged function informs the joystick driver that the configuration has changed and should be reloaded from the registry.
  11.     ''' </summary>
  12.     ''' <param name="dwFlags">Reserved for future use. Must equal zero.</param>
  13.     ''' <returns>
  14.     ''' Returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR if successful. Returns JOYERR_PARMS if the parameter is non-zero.
  15.     ''' </returns>
  16.     ''' <remarks>
  17.     ''' This function causes a window message to be sent to all top-level windows.
  18.     ''' This message may be defined by applications that need to respond to changes in joystick
  19.     ''' calibration by using RegisterWindowMessage with the following message ID:
  20.     ''' #define JOY_CONFIGCHANGED_MSGSTRING     "MSJSTICK_VJOYD_MSGSTR"
  21.     ''' </remarks>
  22.     ''' <see>
  23.     ''' https://msdn.microsoft.com/en-us/library/windows/desktop/dd757104(v=vs.85).aspx
  24.     '''</see>
  25.     <DllImport("winmm.dll")>
  26.     Public Shared Function joyConfigChanged(ByVal dwFlags As Integer) As MMResult
  27.     End Function
  28.  
  29.     ''' <summary>
  30.     ''' The joyGetDevCaps function queries a joystick to determine its capabilities.
  31.     ''' </summary>
  32.     ''' <param name="uJoyID">
  33.     ''' Identifier of the joystick to be queried. Valid values for uJoyID range from -1 to 15.
  34.     ''' A value of -1 enables retrieval of the szRegKey member of the JoyCaps structure whether a device is present or not.
  35.     ''' </param>
  36.     ''' <param name="pjc">
  37.     ''' Pointer to a JoyCaps structure to contain the capabilities of the joystick.
  38.     ''' </param>
  39.     ''' <param name="cbjc">
  40.     ''' Size, in bytes, of the JoyCaps structure.
  41.     ''' </param>
  42.     ''' <returns>
  43.     ''' Returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR if successful or one of the following error values:
  44.     ''' MMSYSERR_NODRIVER: The joystick driver is not present, or the specified joystick identifier is invalid. The specified joystick identifier is invalid.
  45.     ''' MMSYSERR_INVALPARAM: An invalid parameter was passed.
  46.     ''' </returns>
  47.     ''' <remarks>
  48.     ''' Use the joyGetNumDevs function to determine the number of joystick devices supported by the driver.
  49.     ''' This method fails when passed an invalid value for the cbjc parameter.
  50.     ''' </remarks>
  51.     ''' <see>
  52.     ''' https://msdn.microsoft.com/en-us/library/windows/desktop/dd757105(v=vs.85).aspx
  53.     ''' </see>
  54.     <DllImport("winmm.dll")>
  55.     Public Shared Function joyGetDevCaps(ByVal uJoyID As JoyId, ByRef pjc As JoyCaps, ByVal cbjc As Integer) As MMResult
  56.     End Function
  57.  
  58.     ''' <summary>
  59.     ''' The joyGetNumDevs function queries the joystick driver for the number of joysticks it supports.
  60.     ''' </summary>
  61.     ''' <returns>
  62.     ''' The joyGetNumDevs function returns the number of joysticks supported by the current driver or zero if no driver is installed.
  63.     ''' </returns>
  64.     ''' <remarks>
  65.     ''' Use the joyGetPos function to determine whether a given joystick is physically attached to the system.
  66.     ''' If the specified joystick is not connected, joyGetPos returns a JOYERR_UNPLUGGED error value.
  67.     ''' </remarks>
  68.     <DllImport("winmm.dll")>
  69.     Public Shared Function joyGetNumDevs() As Integer
  70.     End Function
  71.  
  72.     ''' <summary>
  73.     ''' The joyGetPos function queries a joystick for its position and button status.
  74.     ''' </summary>
  75.     ''' <param name="uJoyID">
  76.     ''' Identifier of the joystick to be queried. Valid values for uJoyID range from zero (JoyId.JOYSTICK1) to 15.
  77.     ''' </param>
  78.     ''' <param name="pji">
  79.     ''' Pointer to a JoyInfo structure that contains the position and button status of the joystick.
  80.     ''' </param>
  81.     ''' <returns>
  82.     ''' Returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR if successful or one of the following error values.
  83.     ''' MMSYSERR_NODRIVER       The joystick driver is not present.
  84.     ''' MMSYSERR_INVALPARAM     An invalid parameter was passed.
  85.     ''' JOYERR_UNPLUGGED        The specified joystick is not connected to the system.
  86.     ''' </returns>
  87.     ''' <remarks>
  88.     ''' For devices that have four to six axes of movement, a point-of-view control, or more than four buttons, use the joyGetPosEx function.
  89.     ''' </remarks>
  90.     <DllImport("winmm.dll")>
  91.     Public Shared Function joyGetPos(ByVal uJoyID As JoyId, ByRef pji As JoyInfo) As MMResult
  92.     End Function
  93.  
  94.     ''' <summary>
  95.     ''' The joyGetPosEx function queries a joystick for its position and button status.
  96.     ''' </summary>
  97.     ''' <param name="uJoyID">
  98.     ''' Identifier of the joystick to be queried. Valid values for uJoyID range from zero (JoyId.JOYSTICK1) to 15.
  99.     ''' </param>
  100.     ''' <param name="pji">
  101.     ''' Pointer to a JoyInfoEx structure that contains extended position information and button status of the joystick.
  102.     ''' You must set the Size and Flags members or joyGetPosEx will fail. The information returned from joyGetPosEx
  103.     '''  depends on the flags you specify in Flags.
  104.     ''' </param>
  105.     ''' <returns>
  106.     ''' Returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR if successful or one of the following error values.
  107.     ''' MMSYSERR_NODRIVER       The joystick driver is not present.
  108.     ''' MMSYSERR_INVALPARAM     An invalid parameter was passed.
  109.     ''' MMSYSERR_BADDEVICEID    The specified joystick identifier is invalid.
  110.     ''' JOYERR_UNPLUGGED        The specified joystick is not connected to the system.
  111.     ''' JOYERR_PARMS            The specified joystick identifier is invalid.
  112.     ''' </returns>
  113.     ''' <remarks>
  114.     ''' This function provides access to extended devices such as rudder pedals, point-of-view hats,
  115.     ''' devices with a large number of buttons, and coordinate systems using up to six axes.
  116.     ''' For joystick devices that use three axes or fewer and have fewer than four buttons, use the joyGetPos function.
  117.     ''' </remarks>
  118.     <DllImport("winmm.dll")>
  119.     Public Shared Function joyGetPosEx(ByVal uJoyID As JoyId, ByRef pji As JoyInfoEx) As MMResult
  120.     End Function
  121.  
  122.     ''' <summary>
  123.     ''' The joyGetThreshold function queries a joystick for its current movement threshold.
  124.     ''' </summary>
  125.     ''' <param name="uJoyID">
  126.     ''' Identifier of the joystick. Valid values for uJoyID range from zero (JoyId.JOYSTICK1) to 15.
  127.     ''' </param>
  128.     ''' <param name="puThreshold">
  129.     ''' Pointer to a variable that contains the movement threshold value.
  130.     ''' </param>
  131.     ''' <returns>
  132.     ''' Returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR if successful or one of the following error values.
  133.     ''' MMSYSERR_NODRIVER    The joystick driver is not present.
  134.     ''' MMSYSERR_INVALPARAM  An invalid parameter was passed.
  135.     ''' </returns>
  136.     ''' <remarks>
  137.     ''' The movement threshold is the distance the joystick must be moved before a joystick position-change message
  138.     ''' (JoyMessage.MM_JOY1MOVE, JoyMessage.MM_JOY1ZMOVE, JoyMessage.MM_JOY2MOVE, or JoyMessage.MM_JOY2ZMOVE)
  139.     ''' is sent to a window that has captured the device. The threshold is initially zero.
  140.     ''' </remarks>
  141.     <DllImport("winmm.dll")>
  142.     Public Shared Function joyGetThreshold(ByVal uJoyID As JoyId, ByRef puThreshold As UInteger) As MMResult
  143.     End Function
  144.  
  145.     ''' <summary>
  146.     ''' The joyReleaseCapture function releases the specified captured joystick.
  147.     ''' </summary>
  148.     ''' <param name="uJoyID">
  149.     ''' Identifier of the joystick. Valid values for uJoyID range from zero (JoyId.JOYSTICK1) to 15.
  150.     ''' </param>
  151.     ''' <returns>
  152.     ''' Returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR if successful or one of the following error values.
  153.     ''' MMSYSERR_NODRIVER      The joystick driver is not present.
  154.     ''' MMSYSERR_INVALIDPARAM  The specified joystick device identifier uJoyID is invalid.
  155.     ''' JOYERR_PARMS           The specified joystick device identifier uJoyID is invalid.
  156.     ''' </returns>
  157.     ''' <remarks>
  158.     ''' This method returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR when passed a valid joystick identifier that has not been captured.
  159.     ''' </remarks>
  160.     <DllImport("winmm.dll")>
  161.     Public Shared Function joyReleaseCapture(ByVal uJoyID As JoyId) As MMResult
  162.     End Function
  163.  
  164.     ''' <summary>
  165.     ''' The joySetCapture function captures a joystick by causing its messages to be sent to the specified window.
  166.     ''' </summary>
  167.     ''' <param name="hwnd">
  168.     ''' Handle to the window to receive the joystick messages.
  169.     ''' </param>
  170.     ''' <param name="uJoyID">
  171.     ''' Identifier of the joystick. Valid values for uJoyID range from zero (JoyId.JOYSTICK1) to 15.
  172.     ''' </param>
  173.     ''' <param name="uPeriod">
  174.     ''' Polling frequency, in milliseconds.
  175.     ''' </param>
  176.     ''' <param name="fChanged">
  177.     ''' Change position flag. Specify TRUE for this parameter to send messages only when the position
  178.     ''' changes by a value greater than the joystick movement threshold. Otherwise, messages are sent
  179.     ''' at the polling frequency specified in uPeriod.
  180.     ''' </param>
  181.     ''' <returns>
  182.     ''' Returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR if successful or one of the following error values.
  183.     ''' MMSYSERR_NODRIVER    The joystick driver is not present.
  184.     ''' MMSYSERR_INVALPARAM  Invalid joystick ID or hwnd is NULL.
  185.     ''' JOYERR_NOCANDO       Cannot capture joystick input because a required service (such as a Windows timer) is unavailable.
  186.     ''' JOYERR_UNPLUGGED     The specified joystick is not connected to the system.
  187.     ''' JOYERR_PARMS         Invalid joystick ID or hwnd is NULL.
  188.     ''' </returns>
  189.     ''' <remarks>
  190.     ''' If the specified joystick is currently captured, the function returns undefined behavior.
  191.     ''' Call the joyReleaseCapture function to release the captured joystick, or destroy the window
  192.     ''' to release the joystick automatically.
  193.     ''' </remarks>
  194.     <DllImport("winmm.dll")>
  195.     Public Shared Function joySetCapture(ByVal hwnd As IntPtr, ByVal uJoyID As JoyId, ByVal uPeriod As UInteger, ByVal fChanged As Boolean) As MMResult
  196.     End Function
  197.  
  198.     ''' <summary>
  199.     ''' The joySetThreshold function sets the movement threshold of a joystick.
  200.     ''' </summary>
  201.     ''' <param name="uJoyID">
  202.     ''' Identifier of the joystick. Valid values for uJoyID range from zero (JoyId.JOYSTICK1) to 15.
  203.     ''' </param>
  204.     ''' <param name="puThreshold">
  205.     ''' New movement threshold.
  206.     ''' </param>
  207.     ''' <returns>
  208.     ''' Returns MMSYSERR_NOERROR_OR_JOYERR_NOERROR if successful or one of the following error values.
  209.     ''' MMSYSERR_NODRIVER  The joystick driver is not present.
  210.     ''' JOYERR_PARMS       The specified joystick device identifier uJoyID is invalid.
  211.     ''' </returns>
  212.     ''' <remarks>
  213.     ''' The movement threshold is the distance the joystick must be moved before a joystick position-change message
  214.     ''' (JoyMessage.MM_JOY1MOVE, JoyMessage.MM_JOY1ZMOVE, JoyMessage.MM_JOY2MOVE, or JoyMessage.MM_JOY2ZMOVE) is sent to a window that has captured the device.
  215.     ''' The threshold is initially zero.
  216.     ''' </remarks>
  217.     <DllImport("winmm.dll")>
  218.     Public Shared Function joySetThreshold(ByVal uJoyID As JoyId, ByVal puThreshold As UInteger) As MMResult
  219.     End Function
  220.  
  221. End Class 'NativeMethods joystick
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement