# Calling VB6 dll from Ruby

**URL:** <https://www.ruby-forum.com/t/calling-vb6-dll-from-ruby/113284>\
**Category:** Ruby\
**Created:** [August 29, 2007, 3:10pm UTC](https://www.ruby-forum.com/t/calling-vb6-dll-from-ruby/113284 "2007-08-29T15:10:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 29, 2007, 3:10pm UTC](https://www.ruby-forum.com/t/calling-vb6-dll-from-ruby/113284/1 "2007-08-29T15:10:38Z")

</div>

I am trying to use a VB6 dll created by another programmer from Ruby.  
To see what was I opened it in Visual Studio’s object browser. It has  
a series of classes with their methods and properties. I want to acess  
the Load method in the SalesContract class. Here’s my code (which is  
probably wrong)

require ‘Win32API’  
@ops = Win32API.new(‘SMD Client.dll’,‘SalesContract::Load’,‘I’,‘P’)

Here’s the error message I’m getting

C:/Data/Projects/Smd\_Ruby/testdll.rb:2:in `initialize': GetProcAddress: SalesContract::Load or SalesContract::LoadA (RuntimeError) from C:/Data/Projects/Smd_Ruby/testdll.rb:2:in`new’  
from C:/Data/Projects/Smd\_Ruby/testdll.rb:2

I’m not sure that this is even possible. Any help would be greatly  
appreciated.

Luis

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 29, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/calling-vb6-dll-from-ruby/113284/2 "2007-08-29T15:30:40Z")

</div>

On Aug 29, 2:06 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> C:/Data/Projects/Smd\_Ruby/testdll.rb:2:in `initialize': GetProcAddress: SalesContract::Load or SalesContract::LoadA (RuntimeError) from C:/Data/Projects/Smd_Ruby/testdll.rb:2:in `new’  
> from C:/Data/Projects/Smd\_Ruby/testdll.rb:2

I haven’t tried this from Ruby, but VB6 DLLs are actually “ActiveX” or  
COM DLLs, so you should probably be trying to talk to them using the  
Win32OLE library.

HTH,

Mike

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 29, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/calling-vb6-dll-from-ruby/113284/3 "2007-08-29T15:45:43Z")

</div>

On Aug 29, 8:27 am, Mike W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > probably wrong)  
> > from C:/Data/Projects/Smd\_Ruby/testdll.rb:2
> 
> I haven’t tried this from Ruby, but VB6 DLLs are actually “ActiveX” or  
> COM DLLs, so you should probably be trying to talk to them using the  
> Win32OLE library.
> 
> HTH,
> 
> Mike- Hide quoted text -
> 
> - Show quoted text -

I tried registering the dll and using win32ole but didn’t have any  
luck.  
Here’s the code  
require ‘win32ole’  
smd = WIN32OLE.new(‘SMDClient’)

Here’s the error message  
C:/Data/Projects/Smd\_Ruby/testdll.rb:4:in `initialize': unknown OLE server: `SMDClient’ (WIN32OLERuntimeError)  
HRESULT error code:0x800401f3  
Invalid class string from C:/Data/Projects/Smd\_Ruby/testdll.rb:  
4:in `new’  
from C:/Data/Projects/Smd\_Ruby/testdll.rb:4
