Announcement

Collapse
No announcement yet.

Opaque Pointers

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

  • Opaque Pointers

    Hello all,

    When dealing with some of the Windows internals, the APIs often use an "opaque pointer", which is a pointer
    returned by the API to some unknown (to the client) structure, the details of which are unimportant to the
    client. For example, in the SETUPAPI.H file:
    Code:
       //
       // Define type for reference to device information set
       //
       typedef PVOID HDEVINFO;
    From a PB point of view I could just declare this as a LONG or a DWORD, but it isn't always clear what the
    DWORD is actually pointing to.

    My question is, since PB doesn't support TYPEDEFs, could I replace the simple LONG/DWORD declaration with a
    TYPE that contains a LONG/DWORD and thereby gain some code clarity? From the compiler's perspective, are the
    two the same or is there extra overhead with the TYPE statement?
    Code:
       TYPE HDEVINFO
          P AS DWORD
       END TYPE
    
       LOCAL tHdev as HDEVINFO
    
       tHdev.P = SomeFunctionThatReturnsOpaquePtr()
    
       SomeSubThatUsesOpaquePtr(tHdev.P)
    In my current project I've got a number of these opaque pointers in use, and while
    using descriptive variable names helps, it's still something of a mess.

    Thanks!

    ------------------
    Mark Newman
    Mark Newman

  • #2
    Should make no noticeable difference.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Great!

      BTW, is something like TYPEDEF on the wishlist? It'd be handy when porting over Windows-C code,
      something I seem to be doing a lot of lately

      Thanks!

      ------------------
      Mark Newman
      Mark Newman

      Comment


      • #4
        Yep, it's on the wish list.

        ------------------
        Tom Hanlin
        PowerBASIC Staff

        Comment

        Working...
        X