Newbie: Calling dll functions from Ruby for a customer dll

Hello,

I have searched to forum previosly but have found little in the way on
concrete examples. This might just be my inexperience hence the ‘Newbie’
in the title. I want to introduce Ruby into my Python addicted office.
One way I would like to acheive that is by converting some of our useful
scripts to Ruby.

The script essentially calls a dll which was created internally long ago
by our engineers. It controlls a peice of hardware and also quesries it
based on an API which we provide. If I can quickly convert it to Ruby it
would help me to prove its worth. Please have patience with me if I am
being a bit thick here. Here is the initial crux of the code in Python
which I want to Rubify:

import os
import sys
import re
import time
from ctypes import *
from datetime import datetime
from threading import Thread

#Open a file for logging
AutomationLogsPath = os.getcwd()

#Open a file for logging
currentTime = time.strftime(’%d.%m.%y_%H_%M_%S’)
filename = AutomationLogsPath + “\WCDMA_DATACALL” + currentTime +
“.log”
fp = open(filename,“a”)

#Change the current working directory to the one containing dlls.
os.chdir(“C:\Program Files\Aeroflex\7100\Remote Control\Bin”)

try:
h_rrcApi = windll.LoadLibrary(‘afRrcApiInterfaceDll.Dll’)
h_wcdmaApi = windll.LoadLibrary(‘afWCDMAApiInterfaceDll.dll’)
h_ControlLib = windll.LoadLibrary(‘afApplicationControlDll.Dll’)
except WindowsError:
time = datetime.now().isoformat()
fp.write(time + “\tLoadLibrary failed to find the dll!\n”)
print “LoadLibrary failed to find the dll!\n”
fp.close()
exit(-1)

Thank you for reading this.

Imran

An example of calling a method would then be:

ret = h_rrcLib.afRRCLibraryDll_RunTestScript ( “REGISTER”,
len(“REGISTER”), “7100_system_param.xml”, len(“7100_system_param.xml”))

On Nov 23, 2011, at 8:39 AM, Omran N. wrote:

An example of calling a method would then be:

ret = h_rrcLib.afRRCLibraryDll_RunTestScript ( “REGISTER”,
len(“REGISTER”), “7100_system_param.xml”, len(“7100_system_param.xml”))

I recommend taking a look at the win32-utils project. Don’t worry too
much that there haven’t been a lot of updates since 2009; that’s
probably because the sub-project “just work.”

http://rubyforge.org/projects/win32utils/

There is probably some code here that can help you achieve your goal.

cr

Great, thank for your response. I’ll start here. TC

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs