Hi all, Since I didn''t get any takers on the win32-ole rewrite I thought I''d take a stab at starting it. Here''s what I''ve got so far (along with some extra constants in Windows::COM only in CVS), but the call to CoCreateInstance() isn''t working. I''m not sure if I''m dealing with the IDispatch interface properly: # win32/ole.rb require ''windows/com'' require ''windows/com/automation'' require ''windows/error'' require ''windows/unicode'' require ''socket'' module Win32 class OLE include Windows::Error include Windows::COM include Windows::COM::Automation include Windows::Unicode # Error raised if any of the OLE related methods fail. class Error < StandardError; end # The name of the OLE automation server specified in the constructor. attr_reader :server # The host the OLE automation object was created on. attr_reader :host # Did I declare these properly? # http://tinyurl.com/3z8z4h IID_IUnknown = [0,0,0,192,0,0,0,0,0,0,70].pack(''ISSCCCCCCCC'') IID_IDispatch [132096,0,0,192,0,0,0,0,0,0,70].pack(''ISSCCCCCCCC'') IID_IEnumVARIANT [132100,0,0,192,0,0,0,0,0,0,70].pack(''ISSCCCCCCCC'') def initialize(server, host = Socket.gethostname) @server = server @host = host clsid = 0.chr * 16 dispatch = 0.chr * 16 # I''m not sure what hr = CLSIDFromProgID(multi_to_wide(server, CP_UTF8), clsid) if FAILED(hr) hr = CLSIDFromString(multi_to_wide(server, CP_UTF8), clsid) if FAILED(hr) raise Error, "unknown OLE server ''#{server}''" end end # Fails here hr = CoCreateInstance( clsid, nil, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IDispatch, dispatch ) if FAILED(hr) raise Error, "failed to create OLE object from ''#{server}''" end end end end if $0 == __FILE__ include Win32 excel = OLE.new(''excel.application'') End Any ideas? Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.
Hi, 2008/6/5 Berger, Daniel <Daniel.Berger at qwest.com>:> Hi all, > > Since I didn''t get any takers on the win32-ole rewrite I thought I''d > take a stab at starting it. Here''s what I''ve got so far (along with some > extra constants in Windows::COM only in CVS), but the call to > CoCreateInstance() isn''t working. I''m not sure if I''m dealing with the > IDispatch interface properly: > > # win32/ole.rb > require ''windows/com'' > require ''windows/com/automation'' > require ''windows/error'' > require ''windows/unicode'' > require ''socket'' > > module Win32 > class OLE > include Windows::Error > include Windows::COM > include Windows::COM::Automation > include Windows::Unicode > > # Error raised if any of the OLE related methods fail. > class Error < StandardError; end > > # The name of the OLE automation server specified in the > constructor. > attr_reader :server > > # The host the OLE automation object was created on. > attr_reader :host > > # Did I declare these properly? > # http://tinyurl.com/3z8z4h > IID_IUnknown = [0,0,0,192,0,0,0,0,0,0,70].pack(''ISSCCCCCCCC'') > IID_IDispatch > [132096,0,0,192,0,0,0,0,0,0,70].pack(''ISSCCCCCCCC'') > IID_IEnumVARIANT > [132100,0,0,192,0,0,0,0,0,0,70].pack(''ISSCCCCCCCC'') > > def initialize(server, host = Socket.gethostname) > @server = server > @host = host > > clsid = 0.chr * 16 > dispatch = 0.chr * 16 # I''m not sure what > > hr = CLSIDFromProgID(multi_to_wide(server, CP_UTF8), clsid) > > if FAILED(hr) > hr = CLSIDFromString(multi_to_wide(server, CP_UTF8), clsid) > if FAILED(hr) > raise Error, "unknown OLE server ''#{server}''" > end > end > > # Fails here > hr = CoCreateInstance( > clsid, > nil, > CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, > IID_IDispatch, > dispatch > ) > > if FAILED(hr) > raise Error, "failed to create OLE object from ''#{server}''" > end > end > end > end > > if $0 == __FILE__ > include Win32 > excel = OLE.new(''excel.application'') > End > > Any ideas? >The return value of CoCreateInstance() -2147221008 is due to the lack of CoInitialize() call. Insert hr = CoInitialize(nil) before hr = CoCreateInstance seems to work for me. Regards, Park Heesob
Hi, <snip>> The return value of CoCreateInstance() -2147221008 is due to > the lack of CoInitialize() call. > > Insert > hr = CoInitialize(nil) > before > hr = CoCreateInstance > seems to work for me.Makes sense. That worked, thanks. Strange that win32ole.c never calls it. Anyway, I''ve made some initial commits to CVS to the ''win32-ole'' project for those interested. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.