Sha256: 525a63f4c6bdc8861e77544ba7c326da982de33f2084458a4261c54c6acf0aba

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

module DDE

  # Class encapsulates DDE string. In addition to normal string behavior,
  # it also has *handle* that can be passed to dde functions
  class DdeString < String
    include Win::DDE

    attr_accessor :handle, # string handle passable to DDEML functions
                  :instance_id, # instance id of DDE app that created this DdeString
                  :code_page, # Windows code page for this string (CP_WINANSI or CP_WINUNICODE)
                  :name # ORIGINAL string used to create this DdeString

    # Given the DDE application instance_id, you cane create DdeStrings
    # either from regular string or from known DdeString handle
    def initialize(instance_id, string_or_handle, code_page=CP_WINANSI)
      @instance_id = instance_id
      @code_page = code_page

      begin
        if string_or_handle.is_a? String
          @name = string_or_handle
          error unless @handle = dde_create_string_handle(@instance_id, @name, @code_page)
        else
          @handle = string_or_handle
          error unless @name = dde_query_string(@instance_id, @handle, @code_page)
        end
      rescue => e
      end
      raise DDE::Errors::StringError, "Failed to initialize DDE string: #{e}" unless @handle && @name && !e
      super @name
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dde-0.2.8 lib/dde/dde_string.rb
dde-0.2.2 lib/dde/dde_string.rb