robust_excel_ole 1.39 → 1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b55888236ecd8ff3750b2b961c15ba52b67d3525566dc58ff6f6144c4a3d4ac
4
- data.tar.gz: c1585bfc357054685c44cea38aa597bbb6b3e5d9fc5ed97978a81857bf83679a
3
+ metadata.gz: a3d804db077d2eb3c4eaf9a14a0e16cefcf9b6ba62b28f5e72863b76adf1fea8
4
+ data.tar.gz: 72e7f2f169fa6a945380326c22b45921aa34785741fb4380317551db78a42596
5
5
  SHA512:
6
- metadata.gz: 0fc661d429fea1ad21bf62b453e899090e854467b09846b230b86ca2b4f8fb448ed0afe13a1e86dde0c91c8da9fc72a80eb16429588ce6fdb5a1469695f9a16c
7
- data.tar.gz: 0e88736e07de3ff534c10efc4a635b2dffdbaf1f9c962106e4f1773d7422ee516052bbcea21eb2bf3f88b3038d2dbd0409d3734b0f09f20c98700f27e1599736
6
+ metadata.gz: 188397edb880279b9c5510a6b625a11fde2b4c5366de48f90728c4689293d21096c397a4da10fe10f09ae67a234f686906b5245c6f0f9f3750e69a6c95d4ab82
7
+ data.tar.gz: 927aa043117fbbec3fd517ecc9e13ea522aebc87f04bacc84ffcf334df4c7a54f285480ef597bdb2505497ef450862446915dd1d0191e99128c2932f78ba260a
@@ -7,58 +7,64 @@ def ka
7
7
  Excel.kill_all
8
8
  end
9
9
 
10
- =begin
11
10
  module User32
12
11
  # Extend this module to an importer
13
12
  extend Fiddle::Importer
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)'
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
34
37
  end
35
38
 
36
39
  module Oleacc
37
40
  # Extend this module to an importer
38
41
  extend Fiddle::Importer
39
- # Load 'oleacc' dynamic library into this importer
40
- dlload 'oleacc'
41
- # Set C aliases to this importer for further understanding of function signatures
42
- typealias 'HWND', 'HANDLE'
43
- typealias 'HANDLE', 'void*'
44
- typealias 'ppvObject', 'void**'
45
- typealias 'DWORD', 'unsigned long'
46
- typealias 'HRESULT', 'long'
47
- Guid = struct [
48
- 'unsigned long data1',
49
- 'unsigned short data2',
50
- 'unsigned short data3',
51
- 'unsigned char data4[8]'
52
- ]
53
- # Import C functions from loaded libraries and set them as module functions
54
- extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct guid*, ppvObject)'
55
- #typealias 'REFIID', 'struct guid*'
56
- #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, REFIID, ppvObject)'
57
- #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct GUID*, ppvObject)'
58
- #extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, void*, ppvObject)'
59
- #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
60
67
  end
61
- =end
62
68
 
63
69
  module RobustExcelOle
64
70
 
@@ -349,12 +355,16 @@ module RobustExcelOle
349
355
  GC.start
350
356
  sleep 0.1
351
357
  if finishing_living_excel
352
- # if hwnd
353
- # pid_puffer = ' ' * 32
354
- # User32::GetWindowThreadProcessId(hwnd, pid_puffer)
355
- # pid = pid_puffer.unpack('L')[0]
356
- # Process.kill('KILL', pid) rescue nil
357
- # end
358
+ if hwnd
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
367
+ end
358
368
  @@hwnd2excel.delete(hwnd)
359
369
  weak_xl.ole_free if weak_xl.weakref_alive?
360
370
  end
@@ -557,29 +567,30 @@ module RobustExcelOle
557
567
  self.Hwnd == other_excel.Hwnd if other_excel.is_a?(Excel) && alive? && other_excel.alive?
558
568
  end
559
569
 
560
- # def alive?
561
- #msg = 0x2008
562
- #wparam = 0
563
- #lparam = 0
564
- #flags = 0x0000 # 0x0002
565
- #duration = 5000
566
- #lpdw_result_puffer = ' ' * 32
567
- #status = User32::SendMessageTimeoutA(hwnd, msg, wparam, lparam, flags, duration, lpdw_result_puffer)
568
- #result = lpdw_result_puffer.unpack('L')[0]
569
- #status != 0
570
- # end
571
-
572
570
  # returns true, if the Excel instances responds to VBA methods, false otherwise
573
571
  def alive?
574
- @ole_excel.Name
575
- true
576
- rescue
577
- # trace $!.message
578
- false
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
579
592
  end
580
593
 
581
-
582
-
583
594
  # returns unsaved workbooks in known (not opened by user) Excel instances
584
595
  # @private
585
596
  def self.unsaved_known_workbooks
@@ -741,8 +752,12 @@ module RobustExcelOle
741
752
 
742
753
  def focus
743
754
  self.visible = true
744
- status = User32::SetForegroundWindow(@ole_excel.Hwnd)
745
- 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
746
761
  end
747
762
 
748
763
  # @private
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.39"
2
+ VERSION = "1.40"
3
3
  end
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.39'
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: 2022-03-29 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