Announcement

Collapse
No announcement yet.

User Defined Types (UDT) Variable type? Pre-filling?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pierre Bellisle
    replied
    Code:
    typedef VOID (*USB_IDLE_CALLBACK)(
        PVOID Context
        );
     
    typedef struct _USB_IDLE_CALLBACK_INFO {
      USB_IDLE_CALLBACK IdleCallback;
      PVOID IdleContext;
    } USB_IDLE_CALLBACK_INFO, *PUSB_IDLE_CALLBACK_INFO;
    In C, PVOID is a pointer to any type.

    Microsoft says that this structure should contain
    a pointer to the callback routine and
    a pointer to the callback routine context.

    I guess that the following should do the job...

    Code:
    ...
    TYPE USB_IDLE_CALLBACK
      Context  AS DWORD
    END TYPE
     
    TYPE USB_IDLE_CALLBACK_INFO
      IdleCallback AS USB_IDLE_CALLBACK
      IdleContext  AS DWORD
    END TYPE
    ...
    UsbCallbackInfo.IdleCallback.Context = CODEPTR(SomeContextFunction)
    UsbCallbackInfo.IdleContext = CODEPTR(SomeIdleContextFunction)
    ...

    Leave a comment:


  • Cliff Nichols
    replied
    Sorry to bug, but what about PVOID

    From MSDN all I can find is
    Published Protocols And Royalty-Free License
    PVOID

    TBD


    typedef void* PVOID;
    In my case the original block of code was
    Code:
    typedef
    VOID
    (*USB_IDLE_CALLBACK)(
        PVOID Context
        );
    
    typedef struct _USB_IDLE_CALLBACK_INFO {
        USB_IDLE_CALLBACK IdleCallback;
        PVOID IdleContext;
    } USB_IDLE_CALLBACK_INFO, *PUSB_IDLE_CALLBACK_INFO;
    I think I translated incorrectly to
    Code:
    TYPE USB_IDLE_CALLBACK_INFO
         IdleCallback AS USB_IDLE_CALLBACK
         IdleContext AS PVOID
    END TYPE
    (No wonder I am confused, when MSDN documents something as "To Be Determined" )

    Leave a comment:


  • José Roca
    replied
    A WCHAR is a WORD. It contains a 16-bit unicode character.

    Leave a comment:


  • Cliff Nichols
    replied
    One more quick one, is WCHAR an ASCIIZ * 2 ??? (TMK I think PB is pure Ascii but there are ACODE$ and UCODE$ commands, so I am a bit confused)

    Leave a comment:


  • Cliff Nichols
    replied
    Thank You Jose
    That sure saved me a lot of hair-pulling sleepless nights trying to find out what they were.

    Leave a comment:


  • José Roca
    replied
    The ":1" is not a default value. The structure translates to PB as:

    Code:
    TYPE USB_HUB_CAPABILITIES
       HubIs2xCapable AS BIT * 1 IN DWORD
    END TYPE
    USB_CONNECTION_STATUS is not an structure, but an enumeration:

    Code:
    ' enum USB_CONNECTION_STATUS
    %NoDeviceConnected = 0
    %DeviceConnected = 1
    
    '/* failure codes, these map to fail reasons */
    %DeviceFailedEnumeration = 2
    %DeviceGeneralFailure = 3
    %DeviceCausedOvercurrent = 4
    %DeviceNotEnoughPower = 5
    %DeviceNotEnoughBandwidth = 6
    %DeviceHubNestedTooDeeply = 6
    %DeviceInLegacyHub = 8

    Leave a comment:


  • User Defined Types (UDT) Variable type? Pre-filling?

    I am trying to port the UsbIoCtl.h to a PB *.inc file and have run into 2 scenario's that I can not seem to find an answer for.

    The first is if a UDT can be filled with a value at declaration? For example, I have translated
    Code:
    typedef struct _USB_HUB_CAPABILITIES {
        /*
            Unlike the USB_HUB_INFORMATION structure used by
            IOCTL_USB_GET_NODE_INFORMATION, this structure can be extended in the
            future to accomodate more data.  The IOCTL will return only as much
            data as indicated by the size of the request buffer, to maintain
            backward compatibility with older callers that don't know about the
            new data.
        */
    
        ULONG HubIs2xCapable:1;
    
    } USB_HUB_CAPABILITIES, *PUSB_HUB_CAPABILITIES;
    To the below in PB
    Code:
    TYPE USB_HUB_CAPABILITIES
    '*** Unlike the USB_HUB_INFORMATION structure used by IOCTL_USB_GET_NODE_INFORMATION, this structure can be extended in the
    '*** future to accomodate more data.  The IOCTL will return only AS much data as indicated by the size of the request buffer,
    '*** to maintain backward compatibility with older callers that don't know about the new data.
    '     ULONG HubIs2xCapable:1                            '<--- Original Declaration
         HubIs2xCapable AS DWORD                           '<--- Was ULONG
    END TYPE
    But can I declare HubIs2xCapable with a default value of 1? or do I have to do that from one of my functions?

    The other question I have and can not find in documentation is when the variable is not declared as some sort of type. In this case from the C code
    Code:
    typedef enum _USB_CONNECTION_STATUS {
        NoDeviceConnected,
        DeviceConnected,
    
        /* failure codes, these map to fail reasons */
        DeviceFailedEnumeration,
        DeviceGeneralFailure,
        DeviceCausedOvercurrent,
        DeviceNotEnoughPower,
        DeviceNotEnoughBandwidth,
        DeviceHubNestedTooDeeply,
        DeviceInLegacyHub
    } USB_CONNECTION_STATUS, *PUSB_CONNECTION_STATUS;
    I currently have ported to PB as
    Code:
    TYPE USB_CONNECTION_STATUS
         NoDeviceConnected
         DeviceConnected
    '*** Failure codes, these map to fail reasons
         DeviceFailedEnumeration
         DeviceGeneralFailure
         DeviceCausedOvercurrent
         DeviceNotEnoughPower
         DeviceNotEnoughBandwidth
         DeviceHubNestedTooDeeply
         DeviceInLegacyHub
    END TYPE
    and looking up what each variable means from MSDN
    NoDeviceConnected
    Indicates that there is no device connected to the port.
    DeviceConnected
    Indicates that a device was successfully connected to the port.
    DeviceFailedEnumeration
    Indicates that an attempt was made to connect a device to the port, but the enumeration of the device failed.
    DeviceGeneralFailure
    Indicates that an attempt was made to connect a device to the port, but the connection failed for unspecified reasons.
    DeviceCausedOvercurrent
    Indicates that an attempt was made to connect a device to the port, but the attempt failed because of an overcurrent condition.
    DeviceNotEnoughPower
    Indicates that an attempt was made to connect a device to the port, but there was not enough power to drive the device, and the connection failed.
    DeviceNotEnoughBandwidth
    Indicates that an attempt was made to connect a device to the port, but there was not enough bandwidth available for the device to function properly, and the connection failed.
    DeviceHubNestedTooDeeply
    Indicates that an attempt was made to connect a device to the port, but the nesting of USB hubs was too deep, so the connection failed.
    DeviceInLegacyHub
    Indicates that an attempt was made to connect a device to the port of an unsupported legacy hub, and the connection failed.
    I could guess that variables such as NoDeviceConnected and DeviceConnected are longs or Dwords (for 0 or 1), but I would rather get the declaration correct than "guesstimate" what it would be.

    Any help would be appreciated
Working...
X