robust_excel_ole 1.37 → 1.40

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 646308c3740c8716d9fb91b9c0288edc6e915c060bdd713401980608d412119a
4
- data.tar.gz: 379a3bd099724e9cd6adc2542d804d4f4737eafc47742892dbc1ba4914f7b7c2
3
+ metadata.gz: a3d804db077d2eb3c4eaf9a14a0e16cefcf9b6ba62b28f5e72863b76adf1fea8
4
+ data.tar.gz: 72e7f2f169fa6a945380326c22b45921aa34785741fb4380317551db78a42596
5
5
  SHA512:
6
- metadata.gz: '02308d88008a6e7d5362b0c793f1ab4e55025b7df0d19741dbe66775450f672b654c9766ac3e49d6ec840d497b9fa39befd1f66e6d20e5a5539d6cf3eefbc276'
7
- data.tar.gz: 874eaf4089951eb94ac101699198e35981b72084036eb171ec70eb69dc2c135951138f773844b945ff7f4ebbd8d3a4020f3bdaf3f4286f165334e270ada23118
6
+ metadata.gz: 188397edb880279b9c5510a6b625a11fde2b4c5366de48f90728c4689293d21096c397a4da10fe10f09ae67a234f686906b5245c6f0f9f3750e69a6c95d4ab82
7
+ data.tar.gz: 927aa043117fbbec3fd517ecc9e13ea522aebc87f04bacc84ffcf334df4c7a54f285480ef597bdb2505497ef450862446915dd1d0191e99128c2932f78ba260a
@@ -1,7 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module RobustExcelOle
4
+
4
5
  module Cygwin
6
+
7
+ =begin
5
8
  require 'Win32API'
6
9
 
7
10
  @conv_to_full_posix_path =
@@ -38,6 +41,15 @@ module RobustExcelOle
38
41
  buf.delete!("\0")
39
42
  buf
40
43
  end
44
+ =end
45
+
46
+ require "open3"
47
+
48
+ # @private
49
+ def cygpath(options, path)
50
+ Open3.popen3("cygpath #{options} #{path}") { |stdin, stdout, stderr| stdout.read }[0..-2]
51
+ end
52
+
41
53
  module_function :cygpath
42
54
  end
43
55
  end
@@ -10,52 +10,60 @@ end
10
10
  module User32
11
11
  # Extend this module to an importer
12
12
  extend Fiddle::Importer
13
- # Load 'user32' dynamic library into this importer
14
- dlload 'user32'
15
- # Set C aliases to this importer for further understanding of function signatures
16
- typealias 'HWND', 'HANDLE'
17
- typealias 'HANDLE', 'void*'
18
- typealias 'LPCSTR', 'const char*'
19
- typealias 'LPCWSTR', 'const wchar_t*'
20
- typealias 'UINT', 'unsigned int'
21
- typealias 'ppvObject', 'void**'
22
- typealias 'DWORD', 'unsigned long'
23
- typealias 'LPDWORD', 'DWORD*'
24
- typealias 'PDWORD_PTR', 'DWORD**'
25
- typealias 'WPARAM', 'UINT*'
26
- typealias 'LPARAM', 'INT*'
27
- typealias 'LRESULT', 'DWORD'
28
- # Import C functions from loaded libraries and set them as module functions
29
- extern 'DWORD GetWindowThreadProcessId(HWND, LPDWORD)'
30
- extern 'HWND FindWindowExA(HWND, HWND, LPCSTR, LPCSTR)'
31
- extern 'DWORD SetForegroundWindow(HWND)'
32
- extern 'LRESULT SendMessageTimeoutA(HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR)'
13
+ begin
14
+ # Load 'user32' dynamic library into this importer
15
+ dlload 'user32'
16
+ # Set C aliases to this importer for further understanding of function signatures
17
+ typealias 'HWND', 'HANDLE'
18
+ typealias 'HANDLE', 'void*'
19
+ typealias 'LPCSTR', 'const char*'
20
+ typealias 'LPCWSTR', 'const wchar_t*'
21
+ typealias 'UINT', 'unsigned int'
22
+ typealias 'ppvObject', 'void**'
23
+ typealias 'DWORD', 'unsigned long'
24
+ typealias 'LPDWORD', 'DWORD*'
25
+ typealias 'PDWORD_PTR', 'DWORD**'
26
+ typealias 'WPARAM', 'UINT*'
27
+ typealias 'LPARAM', 'INT*'
28
+ typealias 'LRESULT', 'DWORD'
29
+ # Import C functions from loaded libraries and set them as module functions
30
+ extern 'DWORD GetWindowThreadProcessId(HWND, LPDWORD)'
31
+ extern 'HWND FindWindowExA(HWND, HWND, LPCSTR, LPCSTR)'
32
+ extern 'DWORD SetForegroundWindow(HWND)'
33
+ extern 'LRESULT SendMessageTimeoutA(HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR)'
34
+ rescue Fiddle::DLError => e
35
+ #trace "user32.dll not found: #{e}"
36
+ end
33
37
  end
34
38
 
35
39
  module Oleacc
36
40
  # Extend this module to an importer
37
41
  extend Fiddle::Importer
38
- # Load 'oleacc' dynamic library into this importer
39
- dlload 'oleacc'
40
- # Set C aliases to this importer for further understanding of function signatures
41
- typealias 'HWND', 'HANDLE'
42
- typealias 'HANDLE', 'void*'
43
- typealias 'ppvObject', 'void**'
44
- typealias 'DWORD', 'unsigned long'
45
- typealias 'HRESULT', 'long'
46
- Guid = struct [
47
- 'unsigned long data1',
48
- 'unsigned short data2',
49
- 'unsigned short data3',
50
- 'unsigned char data4[8]'
51
- ]
52
- # Import C functions from loaded libraries and set them as module functions
53
- extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct guid*, ppvObject)'
54
- #typealias 'REFIID', 'struct guid*'
55
- #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, REFIID, ppvObject)'
56
- #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct GUID*, ppvObject)'
57
- #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, void*, ppvObject)'
58
- #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct GUID*, ppvObject)'
42
+ begin
43
+ # Load 'oleacc' dynamic library into this importer
44
+ dlload 'oleacc'
45
+ # Set C aliases to this importer for further understanding of function signatures
46
+ typealias 'HWND', 'HANDLE'
47
+ typealias 'HANDLE', 'void*'
48
+ typealias 'ppvObject', 'void**'
49
+ typealias 'DWORD', 'unsigned long'
50
+ typealias 'HRESULT', 'long'
51
+ Guid = struct [
52
+ 'unsigned long data1',
53
+ 'unsigned short data2',
54
+ 'unsigned short data3',
55
+ 'unsigned char data4[8]'
56
+ ]
57
+ # Import C functions from loaded libraries and set them as module functions
58
+ extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct guid*, ppvObject)'
59
+ #typealias 'REFIID', 'struct guid*'
60
+ #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, REFIID, ppvObject)'
61
+ #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct GUID*, ppvObject)'
62
+ #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, void*, ppvObject)'
63
+ #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct GUID*, ppvObject)'
64
+ rescue Fiddle::DLError => e
65
+ #trace "oleacc.dll not found: #{e}"
66
+ end
59
67
  end
60
68
 
61
69
  module RobustExcelOle
@@ -348,10 +356,14 @@ module RobustExcelOle
348
356
  sleep 0.1
349
357
  if finishing_living_excel
350
358
  if hwnd
351
- pid_puffer = ' ' * 32
352
- User32::GetWindowThreadProcessId(hwnd, pid_puffer)
353
- pid = pid_puffer.unpack('L')[0]
354
- Process.kill('KILL', pid) rescue nil
359
+ begin
360
+ pid_puffer = ' ' * 32
361
+ User32::GetWindowThreadProcessId(hwnd, pid_puffer)
362
+ pid = pid_puffer.unpack('L')[0]
363
+ Process.kill('KILL', pid) rescue nil
364
+ rescue NoMethodError => e
365
+ # trace "#{e}"
366
+ end
355
367
  end
356
368
  @@hwnd2excel.delete(hwnd)
357
369
  weak_xl.ole_free if weak_xl.weakref_alive?
@@ -414,6 +426,7 @@ module RobustExcelOle
414
426
  # returns running Excel instances
415
427
  # !!! This is work in progress
416
428
  # the approach is currently restricted to visible Excel instances with at least one workbook
429
+ =begin
417
430
  def self.running_excel_instances
418
431
  win32ole_excel_instances = []
419
432
  hwnd = 0
@@ -478,6 +491,8 @@ module RobustExcelOle
478
491
  alias known_excel_instances known_running_instances # :deprecated: #
479
492
  end
480
493
 
494
+ =end
495
+
481
496
  private
482
497
 
483
498
  # returns a Win32OLE object that represents a Excel instance to which Excel connects
@@ -554,15 +569,26 @@ module RobustExcelOle
554
569
 
555
570
  # returns true, if the Excel instances responds to VBA methods, false otherwise
556
571
  def alive?
557
- msg = 0x2008
558
- wparam = 0
559
- lparam = 0
560
- flags = 0x0000 # 0x0002
561
- duration = 5000
562
- lpdw_result_puffer = ' ' * 32
563
- status = User32::SendMessageTimeoutA(hwnd, msg, wparam, lparam, flags, duration, lpdw_result_puffer)
564
- result = lpdw_result_puffer.unpack('L')[0]
565
- status != 0
572
+ begin
573
+ msg = 0x2008
574
+ wparam = 0
575
+ lparam = 0
576
+ flags = 0x0000 # 0x0002
577
+ duration = 5000
578
+ lpdw_result_puffer = ' ' * 32
579
+ status = User32::SendMessageTimeoutA(hwnd, msg, wparam, lparam, flags, duration, lpdw_result_puffer)
580
+ result = lpdw_result_puffer.unpack('L')[0]
581
+ status != 0
582
+ rescue NoMethodError => e
583
+ #trace "#{e}"
584
+ begin
585
+ @ole_excel.Name
586
+ true
587
+ rescue
588
+ # trace $!.message
589
+ false
590
+ end
591
+ end
566
592
  end
567
593
 
568
594
  # returns unsaved workbooks in known (not opened by user) Excel instances
@@ -726,8 +752,12 @@ module RobustExcelOle
726
752
 
727
753
  def focus
728
754
  self.visible = true
729
- status = User32::SetForegroundWindow(@ole_excel.Hwnd)
730
- raise ExcelREOError, "could not set Excel window as foreground" if status == 0
755
+ begin
756
+ status = User32::SetForegroundWindow(@ole_excel.Hwnd)
757
+ raise ExcelREOError, "could not set Excel window as foreground" if status == 0
758
+ rescue NoMethodError => e
759
+ raise ExcelREOError, "could not set Excel window as foreground because user32.dll not found"
760
+ end
731
761
  end
732
762
 
733
763
  # @private
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.37"
2
+ VERSION = "1.40"
3
3
  end
data/spec/cygwin_spec.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  require_relative 'spec_helper'
3
4
 
5
+ $VERBOSE = nil
6
+
7
+ include RobustExcelOle
8
+ include General
9
+
4
10
  describe "on cygwin", :if => RUBY_PLATFORM =~ /cygwin/ do
5
11
  describe ".cygpath" do
6
12
  context "cygwin path is '/cygdrive/c/Users'" do
@@ -18,25 +24,26 @@ describe "on cygwin", :if => RUBY_PLATFORM =~ /cygwin/ do
18
24
  end
19
25
 
20
26
  context "windows path is 'C:\\Users'" do
21
- context "with '-u option" do
22
- it { RobustExcelOle::Cygwin.cygpath('-u', 'C:\\Users').should eq '/cygdrive/c/Users'}
27
+ context "with '-p option" do
28
+ it { RobustExcelOle::Cygwin.cygpath('-p', 'C:\\Users').should eq '/cygdrive/c/Users'}
23
29
  end
24
30
  end
25
31
 
26
32
  context "cygwin path is './'" do
27
- context "with '-u' options" do
28
- it { RobustExcelOle::Cygwin.cygpath('-u', './').should eq './' }
33
+ context "with '-p' options" do
34
+ it { RobustExcelOle::Cygwin.cygpath('-p', './').should eq './' }
29
35
  end
30
36
 
31
- context "with '-ua' options" do
32
- it { RobustExcelOle::Cygwin.cygpath('-ua', './').should eq File.expand_path('./') + '/' }
33
- end
37
+ # context "with '-pa' options" do
38
+ # it { RobustExcelOle::Cygwin.cygpath('-pa', './').should eq File.expand_path('./') + '/' }
39
+ # end
34
40
 
35
- context "with '-us' options" do
36
- it { RobustExcelOle::Cygwin.cygpath('-us', './').should eq './' }
37
- end
41
+ #context "with '-ps' options" do
42
+ # it { RobustExcelOle::Cygwin.cygpath('-ps', './').should eq './' }
43
+ #end
38
44
  end
39
45
 
40
46
  end
41
47
 
42
48
  end
49
+
Binary file
Binary file
Binary file
data/spec/excel_spec.rb CHANGED
@@ -1922,6 +1922,7 @@ module RobustExcelOle
1922
1922
 
1923
1923
  end
1924
1924
 
1925
+ =begin
1925
1926
  describe "known_running_instances" do
1926
1927
 
1927
1928
  it "should return empty list" do
@@ -1952,7 +1953,7 @@ module RobustExcelOle
1952
1953
  end
1953
1954
 
1954
1955
  end
1955
-
1956
+ =end
1956
1957
  context "with hwnd and hwnd2excel" do
1957
1958
 
1958
1959
  before do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust_excel_ole
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.37'
4
+ version: '1.40'
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry