Announcement

Collapse
No announcement yet.

How to do UNION inside of a TYPE??

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

  • How to do UNION inside of a TYPE??

    What would this look like in PB?
    How would you set the value for OffsetHigh?



    GIVEN:

    Code:
    typedef struct _OVERLAPPED {
    ULONG_PTR Internal;
    ULONG_PTR InternalHigh;
    union {
    struct {
    DWORD Offset;
    DWORD OffsetHigh;
    } DUMMYSTRUCTNAME;
    PVOID Pointer;
    } DUMMYUNIONNAME;
    HANDLE hEvent;
    } OVERLAPPED, *LPOVERLAPPED;
    FROM JOSE INCLUDES:
    Code:
    ' // Size = 20 bytes
    TYPE OVERLAPPED DWORD
       Internal          AS DWORD   ' ULONG_PTR Internal
       InternalHigh      AS DWORD   ' ULONG_PTR InternalHigh
       OVERLAPPED_UNION
       hEvent            AS DWORD   ' HANDLE  hEvent
    END TYPE
    
    ' // Size = 8 bytes
    UNION OVERLAPPED_UNION DWORD
       OVERLAPPED_UNION_STRUCT
       Pointer AS DWORD        ' PVOID Pointer
    END UNION
    PERHAPS SOMETHING LIKE THIS: (Didn't work!)
    Code:
    LOCAL MY_OVERLAPPED  AS OVERLAPPED
    LOCAL MY_OVERLAPPED_UNION_STRUCT AS OVERLAPPED_UNION_STRUCT
    
    MY_OVERLAPPED.MY_OVERLAPPED_UNION_STRUCT.Offset     = 0
    MY_OVERLAPPED.MY_OVERLAPPED_UNION_STRUCT.OffsetHigh = 0

  • #2
    Example:

    Code:
    UNION HD_ITEM_TYPE_UNION
       type       AS DWORD        ' UINT    type      // [in] filter type (defined what pvFilter is a pointer to)
       ' // For compatibility with the PB includes
       dtype      AS DWORD        ' UINT    type      // [in] filter type (defined what pvFilter is a pointer to)
    END UNION
    
    ' // Size = 48 bytes
    TYPE HD_ITEMA DWORD
       Mask       AS DWORD        ' UINT    mask
       cxy        AS LONG         ' int     cxy
       pszText    AS ASCIIZ PTR   ' LPSTR   pszText
       hbm        AS DWORD        ' HBITMAP hbm
       cchTextMax AS LONG         ' int     cchTextMax
       fmt        AS LONG         ' int     fmt
       lParam     AS LONG         ' LPARAM  lParam
       iImage     AS LONG         ' int     iImage  // index of bitmap in ImageList
       iOrder     AS LONG         ' int     iOrder  // where to draw this item
    HD_ITEM_TYPE_UNION
       pvFilter   AS DWORD        ' void *  pvFilter  // [in] fillter data see above
       state      AS DWORD
    END TYPE

    Comment


    • #3
      Thanks Jim!
      But how do you put values in?

      I have these to deal with:
      Code:
      ' // Size = 8 bytes
      TYPE OVERLAPPED_UNION_STRUCT DWORD
         Offset       AS DWORD   ' DWORD Offset
         OffsetHigh   AS DWORD   ' DWORD OffsetHigh
      END TYPE
      
      ' // Size = 8 bytes
      UNION OVERLAPPED_UNION DWORD
         OVERLAPPED_UNION_STRUCT
         Pointer AS DWORD        ' PVOID Pointer
      END UNION
      
      ' // Size = 20 bytes
      TYPE OVERLAPPED DWORD
         Internal          AS DWORD   ' ULONG_PTR Internal
         InternalHigh      AS DWORD   ' ULONG_PTR InternalHigh
         OVERLAPPED_UNION
         hEvent            AS DWORD   ' HANDLE  hEvent
      END TYPE
      
      
      LOCAL MY_OVERLAPPED              AS OVERLAPPED
      LOCAL MY_OVERLAPPED_UNION        AS OVERLAPPED_UNION
      LOCAL MY_OVERLAPPED_UNION_STRUCT AS OVERLAPPED_UNION_STRUCT
      
      MY_OVERLAPPED.MY_OVERLAPPED_UNION.MY_OVERLAPPED_UNION_STRUCT.Offset     = 0
      MY_OVERLAPPED.MY_OVERLAPPED_UNION.MY_OVERLAPPED_UNION_STRUCT.OffsetHigh = 0
      MY_OVERLAPPED.hEvent = GLOBAL_EVENT_WAIT_FOR_OVERLAPPED_READ

      Comment


      • #4
        > But how do you put values in?

        Very easily... if you undestand how unions work.

        Code:
        LOCAL MY_OVERLAPPED AS OVERLAPPED
        MY_OVERLAPPED.Offset = 0
        MY_OVERLAPPED.OffsetHigh = 0
        Code:
        
        
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Well, that is too easy.


          Comment

          Working...
          X