# Wrapping C++ dll in ruby

**URL:** <https://www.ruby-forum.com/t/wrapping-c-dll-in-ruby/93098>\
**Category:** Rails\
**Created:** [April 27, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/wrapping-c-dll-in-ruby/93098 "2007-04-27T15:15:12Z")\
**Posts on this page:** 4\
**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:** [April 27, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/wrapping-c-dll-in-ruby/93098/1 "2007-04-27T15:15:12Z")

</div>

Hello

I’m fairly new to RoR (and Ruby), so please forgive me my possible  
stupid questions.

I have a C++ dll which is like a clientside-accespoint to some  
webservices (for security reasons). Now I want to address the dll from  
ruby code, cause I want to do some functional testing on the services  
it implements.

I read a reference to Ruby Native on  
[http://www.gaffer.org/archives/ruby-native-2](http://www.gaffer.org/archives/ruby-native-2)  
but I 'm not sure this is what I want

so anybody has an idea, that would be great…

---

<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:** [April 27, 2007, 5:16pm UTC](https://www.ruby-forum.com/t/wrapping-c-dll-in-ruby/93098/2 "2007-04-27T17:16:31Z")

</div>

Hello,

Wrapping a C++ DLL is not /that/ difficult but it is not straight.

Ruby is only able to access C (read the README.EXT file in the Ruby  
source code), therefore you need to wrap you C++ in C:

Ruby → C → C++

You might want to try SWIG ([http://www.swig.org](http://www.swig.org)), which creates  
bindings with little effort. The problem with SWIG is the code does  
not feel like Ruby.

Depending on how comprehensive you need your bindings to be and how  
Ruby you want them to be, it might be easier/better you just write a  
few C functions wrapping the C++ clasess and methods you need.

I don’t know if it’s going to help you, but Ruby/DLX might be useful  
too: [http://ruby-dlx.rubyforge.org/index.xhtml](http://ruby-dlx.rubyforge.org/index.xhtml)

–  
Pau Garcia i Quiles  
[http://www.elpauer.org](http://www.elpauer.org)  
(Due to the amount of work, I usually need 10 days to answer)

Quoting “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<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:** [April 28, 2007, 1:46am UTC](https://www.ruby-forum.com/t/wrapping-c-dll-in-ruby/93098/3 "2007-04-28T01:46:34Z")

</div>

You can also try [gaffer.org is for sale](http://www.gaffer.org/archives/category/ruby/) . It  
has some  
good examples of C++ objects bing used in Ruby.

---

<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:** [April 30, 2007, 8:28am UTC](https://www.ruby-forum.com/t/wrapping-c-dll-in-ruby/93098/4 "2007-04-30T08:28:09Z")

</div>

Thanks a lot!

Johan
