I am trying to write an interface between RSPEC (Ruby BDD Flavor) and a Windows application. The application itself is written in an obscure language, but it does have a C API that provides access. I went with Ruby / DL, but I had difficulty getting even the most basic DLL method call to work. Here is what I still have in the gt4r.rb file:
require 'dl/import' module Gt4r extend DL::Importable dlload 'c:\\gtdev\\r321\\bin\\gtvapi'
My reading so far suggests that this is all I need to get started, so I wrote an RSPEC example:
require 'gt4r' @@test_environment = "INCLUDE=C:\\graphtalk\\env\\aiadev\\config\\aiadev.ini" @@normal_user = "BMCHARGUE" describe Gt4r do it 'initializes' do rv = Gt4r.gTD_initialize @@normal_user, @@normal_user, @@test_environment rv.should == 0 end end
And at startup ...
C:\code\GraphTalk>spec -fs -rgt4r gt4r_spec.rb Gt4r - initializes (FAILED - 1) 1) 'Gt4r initializes' FAILED expected: 0, got: 13 (using ==) ./gt4r_spec.rb:9: Finished in 0.031 seconds 1 example, 1 failure
The return value (13) is the actual return code, which means an error, but when I try to add the gTD_get_error_message call to my RSPEC, I cannot get the parameters to work.
I am heading in the right direction and can anyone point out the following that I can try?
Thanks Brett
Follow this question, showing the part that fails when I try to get an error message from my target library:
require 'gt4r' @@test_environment = "INCLUDE=C:\\graphtalk\\env\\aiadev\\config\\aiadev.ini" @@normal_user = "BMCHARGUE" describe Gt4r do it 'initializes' do rv = Gt4r.gTD_initialize @@normal_user, @@normal_user, @@test_environment Gt4r.gTD_get_error_message rv, @msg @msg.should == "" rv.should == 0 end end
I expect the error message to be returned in @msg, but when I start, I get the following:
Gt4r (eval):5: [BUG] Segmentation fault ruby 1.8.6 (2008-08-11) [i386-mswin32] This application has requested the Runtime to terminate it in an unusual way. Please contact the application support team for more information.
And if I use the symbol (: msg) instead:
C:\code\GraphTalk\gt4r_dl>spec -fs -rgt4r gt4r_spec.rb Gt4r - initializes (ERROR - 1) 1) NoMethodError in 'Gt4r initializes' undefined method `to_ptr' for :msg:Symbol (eval):5:in `call' (eval):5:in `gTD_get_error_message' ./gt4r_spec.rb:9: Finished in 0.046 seconds 1 example, 1 failure
It's clear that I'm missing something about passing parameters between ruby ββand C, but what?