# Calling VB DLL from ruby code

**URL:** <https://www.ruby-forum.com/t/calling-vb-dll-from-ruby-code/67613>\
**Category:** Ruby\
**Created:** [September 5, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/calling-vb-dll-from-ruby-code/67613 "2006-09-05T17:31:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![medha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c77e96/32.png) [@medha](https://www.ruby-forum.com/u/medha)\
**Post date:** [September 5, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/calling-vb-dll-from-ruby-code/67613/1 "2006-09-05T17:31:13Z")

</div>

I am facing a problem while calling a VB DLL (for which I do not have a  
source code, just know the function signatures which DLL exposes) from a  
ruby code.  
DLL Function signature is as follows:

Public Declare Function GetContentsStream Lib  
“C:\VisualCsource\SLStrucStorageContents\Debug\SSGetContents.dll” \_  
'(arg1 As Byte, \_  
’ ByVal lElements As Long, \_  
’ ByVal sStreamName As String) As Long  
Following is the explanation given by DLL author regarding argument  
types & how that DLL should be called:

lLen = GetContentsStream(arrayObj(0), UBound(arrayObj), sStreamName)

Parameter1: arrayObj is an array of Bytes. We pass the the first  
element of the  
array by Reference, arrayObj (0), which really means we are passing the  
address of the  
start of the array.  
Parameter2: Ubound (arrayObj) is the length of the array.  
Parameter3: Stream name of type string.

I have written following code to call this dll:

require â??Win32APIâ??  
getdllfun = Win32API.new(‘C:\WINDOWS\system32\SSGetContents.dll’,  
â??GetContentsStream", [‘P’,‘L’,‘P’], ‘L’)  
sStreamName = “CONTENTS”  
arrayObj=New Array

## arrayObj stores some binary bitmap data

val=getdllfun.Call  
(GetContentsStream.Call, arrObj.pack(â??C\*â?),arrObj.size,sStreamName)  
puts "\n value: " + val.to\_s

When I execute this code, I get following error while executing function  
getdllgun.Call:

storeLOBData.rb:211: in `fgetContentsStream’: uninitialized constant  
GetContentsS  
tream (NameError)

May be there is a problem with argument types which I am specifying  
i.e. [‘P’,‘L’,‘P’] & argument which I am passing to DLL.  
Any help regarding mapping VB parameter types to Ruby would be really  
appreciated.

Thanks and Regards,  
Medha.

---

<div class="post-metadata">

**Author:** ![medha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c77e96/32.png) [@medha](https://www.ruby-forum.com/u/medha)\
**Post date:** [September 5, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/calling-vb-dll-from-ruby-code/67613/2 "2006-09-05T18:34:03Z")

</div>

On 9/5/06, Medha K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Following is the explanation given by DLL author regarding argument  
> start of the array.
> 
> ## arrayObj stores some binary bitmap data
> 
> tream (NameError)
> 
> May be there is a problem with argument types which I am specifying  
> i.e. [‘P’,‘L’,‘P’] & argument which I am passing to DLL.  
> Any help regarding mapping VB parameter types to Ruby would be really  
> appreciated.
> 
> Thanks and Regards,  
> Medha.

[disclaimer] I am not an expert on the Win32 API [/disclaimer]

Your problem does not look like an argument problem. It is ruby  
telling you that the constant ‘GetContentsStream’ does not exist. I  
wonder what it is doing there. Perhaps you meant:

val = getdllfun.Call(arrObj.pack(“C\*”),arrObj.size,sStreamName)

Reading error messages can help you. Don’t jump to conclusions.
