global function DrawText(atom id, sequence text, atom text_len,
                           sequence format_dim, atom format_opt,
                            object addl_format)

      sequence rtn_val
      atom hDc, text_buf, dtparms, ok, rect
      integer text_height

      -- DO NOT get the DC of the passed id --
      --- DP ---
       --- hDc = getDC(id)

      -- Assign the font
      hDc = assignFont(id)

      -- Allocate the string
      text_buf = acquire_mem(0, text)

      -- Allocate a buffer to hold the rectangle information
      rect = acquire_mem( 0, SIZEOF_RECT )
      store( rect, rectLeft,   format_dim[1] )
      store( rect, rectTop,    format_dim[2] )
      store( rect, rectRight,  format_dim[3] )
      store( rect, rectBottom, format_dim[4] )

      dtparms = 0

      text_height = w32Func(xDrawTextEx, {hDc, text_buf, text_len, rect,
                                         format_opt, dtparms})

      -- Now get the values that can be modified by DrawTextEx
      rtn_val = {}
      rtn_val = append(rtn_val, text_height)
      rtn_val = append(rtn_val, peek_string(text_buf))
      rtn_val = append(rtn_val, fetch(rect, rectLeft))
      rtn_val = append(rtn_val, fetch(rect, rectTop))
      rtn_val = append(rtn_val, fetch(rect, rectRight))
      rtn_val = append(rtn_val, fetch(rect, rectBottom))

      -- Release memory allocated
      release_mem(text_buf)
      release_mem(rect)

      if sequence(addl_format) then
          release_mem(dtparms)
      end if

      -- replace the font with the default again
      --replaceObject( id, hDc, DefaultFontID, ForProgram )

      -- Release the device context
      releaseDC( id )

      return rtn_val

end function
