win 0.1.26 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.26
1
+ 0.1.27
data/lib/win/dde.rb CHANGED
@@ -281,7 +281,7 @@ module Win
281
281
  DMLERR_EXECACKTIMEOUT => 'A request for a synchronous execute transaction has timed out.',
282
282
  DMLERR_INVALIDPARAMETER => 'A parameter failed to be validated by the DDEML. Possible causes: ' +
283
283
  'Application used a data handle initialized with a different item name handle than was required ' +
284
- 'by the transaction.' +
284
+ 'by the transaction. ' +
285
285
  'The application used a data handle that was initialized with a different clipboard data format ' +
286
286
  'than was required by the transaction. ' +
287
287
  'The application used a client-side conversation handle with server-side function or vice versa. ' +
@@ -755,7 +755,7 @@ module Win
755
755
  &->(api, old_id=0, cmd, &block){
756
756
  raise ArgumentError, 'No callback block' unless block
757
757
  old_id = 0 unless old_id
758
- id = FFI::MemoryPointer.new(:long).put_uint32(0, old_id)
758
+ id = FFI::MemoryPointer.new(:uint32).put_uint32(0, old_id)
759
759
  status = api.call(id, block, cmd, 0)
760
760
  id = status == 0 ? id.get_uint32(0) : nil
761
761
  [id, status] }
@@ -779,7 +779,6 @@ module Win
779
779
  #
780
780
  function :DdeUninitialize, [:uint32], :int, boolean: true
781
781
 
782
-
783
782
  ##
784
783
  # The DdeCreateStringHandle function creates a handle that identifies the specified string.
785
784
  # A Dynamic Data Exchange (DDE) client or server application can pass the string handle as a
@@ -814,7 +813,8 @@ module Win
814
813
  #
815
814
  function :DdeCreateStringHandle, [:uint32, :pointer, :int], :ulong, zeronil: true,
816
815
  &->(api, instance_id, string, code_page=CP_WINANSI){
817
- api.call(instance_id, FFI::MemoryPointer.from_string(string), code_page) }
816
+ string_pointer = FFI::MemoryPointer.from_string(string)
817
+ api.call(instance_id, string_pointer, code_page) }
818
818
 
819
819
  ##
820
820
  # The DdeFreeStringHandle function frees a string handle in the calling application.
@@ -1117,7 +1117,7 @@ module Win
1117
1117
  # data_handle = dde_client_transaction(data_pointer, size, conv, item, format, type, timeout, result)
1118
1118
  #
1119
1119
  function :DdeClientTransaction, [:pointer, :uint32, :ulong, :ulong, :uint, :uint, :uint32, :pointer],
1120
- :HDDEDATA, boolean: true
1120
+ :HDDEDATA, zeronil: true
1121
1121
 
1122
1122
  ##
1123
1123
  # The DdeGetData function copies data from the specified Dynamic Data Exchange (DDE) object to the specified
@@ -1200,9 +1200,9 @@ module Win
1200
1200
  #
1201
1201
  function :DdeAccessData, [:HDDEDATA, :pointer], :pointer,
1202
1202
  &->(api, data_handle){
1203
- size_buffer = FFI::MemoryPointer.new(:int16)
1203
+ size_buffer = FFI::MemoryPointer.new(:uint32)
1204
1204
  buffer = api.call(data_handle, size_buffer)
1205
- size = size_buffer.get_int16(0)
1205
+ size = size_buffer.get_uint32(0)
1206
1206
  size == 0 ? [nil, 0] : [buffer, size] }
1207
1207
  # weird lambda literal instead of block is needed because RDoc goes crazy if block is attached to meta-definition
1208
1208
 
data/lib/win/library.rb CHANGED
@@ -63,7 +63,7 @@ module Win
63
63
  @namespace.send(@function_name.to_sym, *args)
64
64
  end
65
65
 
66
- alias_method :[], :call
66
+ # alias_method :[], :call
67
67
  end
68
68
 
69
69
  # Contains class methods (macros) that can be used in any module mixing in Win::Library
@@ -355,11 +355,11 @@ module Win
355
355
  end
356
356
  else
357
357
  if zeronil
358
- ->(*args, &block){ (res = block ? block[api[*args]] : api[*args]) != 0 ? res : nil }
358
+ ->(*args, &block){ (res = block ? block[api.call(*args)] : api.call(*args)) != 0 ? res : nil }
359
359
  elsif boolean
360
- ->(*args, &block){ block ? block[api[*args]] : api[*args] != 0 }
360
+ ->(*args, &block){ block ? block[api.call(*args)] : api.call(*args) != 0 }
361
361
  else
362
- ->(*args, &block){ block ? block[api[*args]] : api[*args] }
362
+ ->(*args, &block){ block ? block[api.call(*args)] : api.call(*args) }
363
363
  end
364
364
  end
365
365
 
data/spec/win/dde_spec.rb CHANGED
@@ -6,7 +6,7 @@ module WinDDETest
6
6
  include Win::DDE
7
7
  include Win::GUI::Message
8
8
 
9
- POKE_STRING = "Poke_string\x00\x00"
9
+ POKE_STRING = "Poke_string"
10
10
 
11
11
  def dde_cmd
12
12
  APPCLASS_STANDARD
@@ -346,31 +346,40 @@ module WinDDETest
346
346
  before(:each) do
347
347
  setup_server do |*args|
348
348
  @server_calls << extract_values(*args)
349
- @data, size = dde_get_data(args[5]) if args.first == XTYP_POKE || args.first == XTYP_EXECUTE
349
+ @data_out, size = dde_get_data(args[5]) if args.first == XTYP_POKE || args.first == XTYP_EXECUTE
350
350
  DDE_FACK
351
351
  end
352
+ @conv_handle = dde_connect( @server_id, @service_handle, @topic_handle, context=nil)
353
+ @data_in = FFI::MemoryPointer.from_string POKE_STRING
352
354
  end
353
355
  after(:each) { teardown_server}
354
356
 
355
357
  spec{ use{ DdeClientTransaction(data=nil, size=0, conv=0, item=0, format=0, type=0, timeout=0, result=nil) }}
356
358
  spec{ use{ dde_client_transaction(data=nil, size=0, conv=0, item=0, format=0, type=0, timeout=0, result=nil) }}
357
359
 
360
+
361
+ it "returns 0/nil if initiated transaction unsuccessful" do
362
+ res = DdeClientTransaction(@data_in, @data_in.size, 1234, @topic_handle, CF_TEXT, XTYP_POKE, 1000, nil)
363
+ res.should == 0 # wrong conversation handle
364
+ res = dde_client_transaction(@data_in, @data_in.size, 1234, @topic_handle, CF_TEXT, XTYP_POKE, 1000, nil)
365
+ res.should == nil # wrong conversation handle
366
+ res = dde_client_transaction(@data_in, @data_in.size, @conv_handle, 0, CF_TEXT, XTYP_POKE, 1000, nil)
367
+ res.should == nil # wrong item handle (cannot be NULL in XTYP_POKE transaction)
368
+ @server_calls.any? {|call| call[0] == 'XTYP_POKE'}.should be_false
369
+ end
370
+
358
371
  it "original api is used by CLIENT to begins a data transaction with server" do
359
- @conv_handle = dde_connect( @server_id, @service_handle, @topic_handle, context=nil)
360
- str = FFI::MemoryPointer.from_string POKE_STRING
361
- res = DdeClientTransaction(str, str.size, @conv_handle, @topic_handle, CF_TEXT, XTYP_POKE, 1000, nil)
372
+ res = DdeClientTransaction(@data_in, @data_in.size, @conv_handle, @topic_handle, CF_TEXT, XTYP_POKE, 1000, nil)
362
373
  res.should == 1
363
- @server_calls.any? {|call| call[0] = 'XTYP_POKE'}.should be_true
364
- @data.read_string.should == POKE_STRING.rstrip
374
+ @server_calls.any? {|call| call[0] == 'XTYP_POKE'}.should be_true
375
+ @data_out.read_string.should == POKE_STRING.rstrip
365
376
  end
366
377
 
367
378
  it "snake_case api begins a data transaction between a client and a server" do
368
- str = FFI::MemoryPointer.from_string POKE_STRING
369
- @conv_handle = dde_connect( @server_id, @service_handle, @topic_handle, context=nil)
370
- res = dde_client_transaction(str, str.size, @conv_handle, @topic_handle, 0, XTYP_EXECUTE, 1000, nil)
371
- res.should == true
372
- @server_calls.any? {|call| call[0] = 'XTYP_EXECUTE'}.should be_true
373
- @data.read_string.should == POKE_STRING.rstrip
379
+ res = dde_client_transaction(@data_in, @data_in.size, @conv_handle, 0, 0, XTYP_EXECUTE, 1000, nil)
380
+ res.should be_true
381
+ @server_calls.any? {|call| call[0] == 'XTYP_EXECUTE'}.should be_true
382
+ @data_out.read_string.should == POKE_STRING.rstrip
374
383
  end
375
384
  end # describe dde_client_transaction
376
385
 
@@ -398,10 +407,10 @@ module WinDDETest
398
407
  data, size = dde_get_data(data_handle)
399
408
  data.should be_an FFI::MemoryPointer
400
409
  data.read_string.should == POKE_STRING.rstrip
401
- size.should == 14
402
- DdeGetData(data_handle, nil, 0, 0).should == 14
410
+ size.should == 12
411
+ DdeGetData(data_handle, nil, 0, 0).should == 12
403
412
  data = FFI::MemoryPointer.new(:char, 1024)
404
- DdeGetData(data_handle, data, data.size, 0).should == 14
413
+ DdeGetData(data_handle, data, data.size, 0).should == 12
405
414
  data.read_string.should == POKE_STRING.rstrip
406
415
  end
407
416
  DDE_FACK
@@ -442,10 +451,10 @@ module WinDDETest
442
451
  data, size = dde_access_data(data_handle)
443
452
  data.should be_kind_of FFI::Pointer
444
453
  data.read_string.should == POKE_STRING.rstrip
445
- size.should == 14
454
+ size.should == 12
446
455
  buf = FFI::MemoryPointer.new(:int16)
447
456
  data = DdeAccessData(data_handle, buf)
448
- buf.get_int16(0).should == 14
457
+ buf.get_int16(0).should == 12
449
458
  data.should be_kind_of FFI::Pointer
450
459
  data.read_string.should == POKE_STRING.rstrip
451
460
  dde_unaccess_data(data_handle)
data/win.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{win}
8
- s.version = "0.1.26"
8
+ s.version = "0.1.27"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["arvicco"]
12
- s.date = %q{2010-03-17}
12
+ s.date = %q{2010-03-23}
13
13
  s.description = %q{Rubyesque interfaces and wrappers for Windows API functions pre-defined using FFI }
14
14
  s.email = %q{arvitallian@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - arvicco
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-17 00:00:00 +03:00
12
+ date: 2010-03-23 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency