From: V KANETKAR Date: 2004-03-03T14:04:51+09:00 Subject: Re: Accessing DLL from Ruby ------=_NextPartTM-000-07e80f3e-64ef-41b9-b59a-ce26ecb9a8be Content-Type: multipart/alternative; boundary="----=_NextPart_000_001B_01C4010D.39816340" ------=_NextPart_000_001B_01C4010D.39816340 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Bob Thanks for the prompt help. I will try this. Now I can convince my colleagues to use Ruby! V V Kanetkar ----- Original Message -----=20 From: Bob Calco=20 To: ruby-core@ruby-lang.org=20 Sent: Wednesday, March 03, 2004 9:49 AM Subject: Re: Accessing DLL from Ruby V.V.: =20 This is because VB dll's are ActiveX dlls; they adhere to the COM = binary specification, and do not export their functions via the C = calling convention (cdecl). You would do well to register the VB dll = (regsvr32.exe at the command line), find its program ID (for = instance, MS Word's is "Word.Application") - something you can do either = by searching the registry, or by selecting it from the available list = inside of MS Office VBA development environment (Go to = Tools->References, a list of all registered COM servers will magically = appear; one of them should be your prjCalc.dll if you successfully = registered it). =20 The point is, once you get the VB DLL's Program ID, you can do this = instead in Ruby: =20 require 'win32ole' =20 MyDLL =3D WIN32OLE.new("") res =3D MyDLL.calc() puts res.to_s =20 - Bob Calco =20 -------------------------------------------------------------------------= ----- From: V KANETKAR [mailto:v_kanetkar@datamatics.com]=20 Sent: Tuesday, March 02, 2004 10:56 PM To: ruby-core@ruby-lang.org Subject: Accessing DLL from Ruby =20 I have a problem: I am trying to call a function from a Visual Basic DLL. I wrote = following code but Ruby gave error. I need to resolve this and need expert Ruby?windows help. =20 #Ruby Program to load dll(Just loading) require 'Win32API' = dllcalc=3DWin32API.new("E:\\download\\sudha\\prjCalc.dll","calc",["I"],'I= ') =20 # Error=20 =20 >ruby dmapi.rb dmapi.rb:2:in `initialize': GetProcAddress: calc or calcA = (RuntimeError) from dmapi.rb:2:in `new' from dmapi.rb:2 >Exit code: 1 =20 =20 =20 # The Visual Basic Code for the dll. Contains only one function calc. = Returns integer, i/p is one integer # Works OK in VB. The dll was registered in Registry: same error. =20 Public Function calc(intVal1 As Integer) As Integer calc =3D -intVal1 End Function =20 =20 =20 # A similar example given in "Pragmatic Programmer" works finr! =20 # Please Help =20 V V Kanetkar ------=_NextPart_000_001B_01C4010D.39816340 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi Bob
Thanks for the prompt = help.
I will try this. Now I can convince my = colleagues=20 to use Ruby!
 
V V Kanetkar
----- Original Message -----
From:=20 Bob = Calco=20
Sent: Wednesday, March 03, 2004 = 9:49=20 AM
Subject: Re: Accessing DLL from = Ruby

V.V.:

 

This is = because VB=20 dll’s are ActiveX dlls; they adhere to the COM binary = specification, and do=20 not export their functions via the C calling convention (cdecl). You = would do=20 well to register the VB dll (regsvr32.exe <dllname> at the = command=20 line), find its program ID (for instance, MS Word’s is = “Word.Application”) –=20 something you can do either by searching the registry, or by selecting = it from=20 the available list inside of MS Office VBA development environment (Go = to=20 Tools->References, a list of all registered COM servers will = magically=20 appear; one of them should be your prjCalc.dll if you successfully = registered=20 it).

 

The point = is, once=20 you get the VB DLL’s Program ID, you can do this instead in=20 Ruby:

 

require=20 ‘win32ole’

 

MyDLL =3D=20 = WIN32OLE.new(“<program_id>”)

res =3D=20 MyDLL.calc(<number>)

puts=20 res.to_s

 

-         =20 Bob=20 Calco

 


From: V=20 KANETKAR [mailto:v_kanetkar@datamatics.com]
Sent:
Tuesday, March 02, 2004 = 10:56=20 PM
To:=20 ruby-core@ruby-lang.org
Subject: Accessing DLL from=20 Ruby

 

I have a=20 problem:

I am trying to call a = function=20 from a Visual Basic DLL. I wrote following code but Ruby gave=20 error.

I need to resolve this = and need=20 expert Ruby?windows help.

 


#Ruby Program to = load dll(Just=20 loading)
require=20 = 'Win32API'
dllcalc=3DWin32API.new("E:\\download\\sudha\\prjCalc.dll","= calc",["I"],'I')

 


# Error=20

 

>ruby = dmapi.rb
dmapi.rb:2:in=20 `initialize': GetProcAddress: calc or calcA = (RuntimeError)
 from=20 dmapi.rb:2:in `new'
 from dmapi.rb:2
>Exit code:=20 1

 

 

 

# The Visual Basic Code = for the=20 dll. Contains only one function calc. Returns integer, i/p is one = integer
#=20 Works OK in VB. The dll was registered in Registry: same=20 error.

 

Public Function = calc(intVal1 As=20 Integer) As Integer
    calc =3D -intVal1
End=20 Function

 

 

 


# A similar example = given in=20 "Pragmatic Programmer"  works = finr!

 

# Please=20 Help

 

V V=20 = Kanetkar

------=_NextPart_000_001B_01C4010D.39816340-- ------=_NextPartTM-000-07e80f3e-64ef-41b9-b59a-ce26ecb9a8be--