Announcement

Collapse
No announcement yet.

Casting ? (C Conversion)

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

  • Casting ? (C Conversion)

    I'm playing around with the ImgSource dll and ran into a "C"
    snag concerning pointers.
    C Code:
    // To get a pointer to the data, cast the HGLOBAL hImg to a BYTE*
    BYTE *pRGB = (BYTE *) hImg;
    It appears to be defining pRGB as a BYTE pointer, but whats going
    on with the casting? Any help would be appreciated.
    Yeah, I'm in over my head, but its fun!
    Jim Warrick


    ------------------

  • #2
    No special casting is necessary in PowerBASIC. LONG, DWORD, and PTR
    types are compatible. You'll end up with something like this:
    Code:
       LOCAL hImg AS DWORD
       LOCAL pRGB AS BYTE PTR
     
       pRGB = hImg
    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      You have to cast, because
      Code:
          BYTE *pRGB = hImg;
      would generate an error. If you translate to PB,
      then you dont need to caste: This is ok
      Code:
          local pRGB as byte pointer : pRGB = hImg
      Regards
      Peter

      ------------------
      [email protected]
      www.dreammodel.dk
      [email protected]
      www.dreammodel.dk

      Comment


      • #4
        Thank you Tom and Peter for your replies. I'll give a shot.

        Jim Warrick

        ------------------

        Comment


        • #5
          In case that won't work - I often encounter strange descriptions in C++
          that turns out they were referring to a handle to memory, and so I have
          to GlobalLock to get pointer to data.

          Thought I'd tell, in case they wrote "cast" but meant something else,
          like "lock". Is not unusual that happens..


          ------------------
          http://www.tolkenxp.com/pb
          Download: incLean, PBcodec, custom controls and code, etc.
          Borje Hagsten - [email protected]

          Comment


          • #6
            Thanks, Borje. I'll get back into the project this morning and
            check it out.

            Jim Warrick

            ------------------

            Comment


            • #7
              I often encounter strange descriptions in C++ ...that turns out they were referring to a handle to memory, and so I have to GlobalLock to get pointer to data
              That's more the 'C' programmer being 'cute' than anything else.

              There is a set of flags you can use with GlobalAlloc (GHND?) which resulst in GlobalAlloc returning a pointer rather than a handle. "If" you use those flags for GlobalAlloc, you get away with this. (And I "think" you always get away with using the handle as a pointer under Win 9x/ME, but not so under Win NT/2K/XP.)

              But it costs nothing and always works to use GlobalLock/GlobalUnlock on whatever is returned by GlobalAlloc.

              MCM

              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X