# Calling DLL from Ruby

**URL:** <https://www.ruby-forum.com/t/calling-dll-from-ruby/98910>\
**Category:** Ruby\
**Created:** [July 18, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/calling-dll-from-ruby/98910 "2006-07-18T23:42:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chintakrindi\_Meghan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b19c9b/32.png) [@Chintakrindi\_Meghan](https://www.ruby-forum.com/u/Chintakrindi_Meghan)\
**Post date:** [July 18, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/calling-dll-from-ruby/98910/1 "2006-07-18T23:42:29Z")

</div>

Hi All

Recently I was trying to call an open source tool (STAF) from  
Watir(Ruby).

I am supposed to call DDVariableStore.dll

But when the program is being executed, I get the error :-

D:/Program Files/Watir/unittests/11.rb:6:1n ‘initialize’:  
GetProcAddress: STAFUtilities or STAFUtilitiesA   
from D:/Program Files/Watir/unittests/11.rb:6

The program code is

require ‘Watir’  
require ‘Win32API’

class STAF\_Watir\_Interface

def processRequest(otrd)

oresult = Win32API.new(“DDVariableStore”,“STAFResult”,"","")

ostaf = otrd.getSTAFHelper()

status = ostaf.sendQueueMessage(debuglog, sinfo & “HookScript  
processing request…”)

otrd.setStatusCode(-1)  
otrd.setStatusInfo("")

message = "I did good on line "& otrd.getLineNumber()  
details = “I deserve something special!”

status = ostaf.logPassedMessage(otrd.getFac(), message, details,  
oresult)

processRequest = otrd.getStatusCode()  
end

engine = “SAFS/Watir”

shutdown = “False”

astaf = Win32API.new (“DDVariableStore”,“STAFUtilities”,"","")  
otrd = Win32API.new(“DDVariableStore”,“TestRecordData”,"","")  
oresult = Win32API.new(“DDVariableStore”,“STAFResult”,"","")

otrd.setSTAFHelper(ostaf)

status = ostaf.registerNewProcess(engine)

handleid = ostaf.getHandleID()

status = ostaf.sendQueueMessage(debuglog, sinfo & “HookScript  
initializing…”)  
status = ostaf.resetHookEvents(engine)  
status = ostaf.postEvent(engine & “Start”)

while (shutdown == False) do

status = ostaf.sendQueueMessage(debuglog, sinfo & “HookScript Ready”)  
status = ostaf.postEvent(engine & “Ready”)  
status = ostaf.getNextHookTestEvent(engine)  
status = ostaf.sendQueueMessage(debuglog, sinfo & “HookScript  
Dispatched”)

```
 otrd.reinitialize()

 status = ostaf.getTestRecordDataVariant(otrd)

 record = otrd.getInputRecord()

 if record == "SHUTDOWN_HOOK" then

```

shutdown = “True”  
end

if (shutdown == “False”) then  
status = processRequest(otrd)  
status = ostaf.sendQueueMessage(debuglog, sinfo & "HookScript  
Results: "& status)  
status = ostaf.sendTestRecordResultsVariant (otrd)  
status = ostaf.setHookTestResultsEvents(engine, 2)  
status = ostaf.resetEvent(engine & “Running”)  
else  
status = ostaf.sendQueueMessage(debuglog, sinfo & “HookScript  
Shutting Down”)  
status = ostaf.postEvent(engine &“Results”)  
end  
end

status = ostaf.resetHookEvents(engine)  
status = ostaf.postEvent(engine &“Shutdown”)  
status = ostaf.sendQueueMessage(debuglog, sinfo & “HookScript  
Shutdown”)  
status = ostaf.unRegisterProcess ()

end

Please correct me if my code is wrong.

Please crosscheck if Win32API was used properly.

The problem starts at this line ---- astaf =  
Win32API.new(“DDVariableStore”,“STAFUtilities”,"","")

Bye and Thanx in advance

Meghanath

---

<div class="post-metadata">

**Author:** ![Chintakrindi\_Meghan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b19c9b/32.png) [@Chintakrindi\_Meghan](https://www.ruby-forum.com/u/Chintakrindi_Meghan)\
**Post date:** [July 19, 2006, 1:34am UTC](https://www.ruby-forum.com/t/calling-dll-from-ruby/98910/2 "2006-07-19T01:34:22Z")

</div>

On 7/18/06, Chintakrindi Meghanath  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi All
> 
> Recently I was trying to call an open source tool (STAF) from Watir(Ruby).
> 
> I am supposed to call DDVariableStore.dll
> 
> But when the program is being executed, I get the error :-
> 
> D:/Program Files/Watir/unittests/11.rb:6:1n ‘initialize’: GetProcAddress: STAFUtilities or STAFUtilitiesA   
> from D:/Program Files/Watir/unittests/11.rb:6

That means Win32API couldn’t find a method called “STAFUtilities” in  
the DLL “DDVariableStore.DLL”. I guess you should check to see if it’s  
really there or if it’s defined in some other DLL.

Regards,  
Sean
