# Ruby extension problem

**URL:** <https://www.ruby-forum.com/t/ruby-extension-problem/182277>\
**Category:** Ruby\
**Created:** [January 25, 2010, 11:10pm UTC](https://www.ruby-forum.com/t/ruby-extension-problem/182277 "2010-01-25T23:10:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philliam\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@Philliam\_A](https://www.ruby-forum.com/u/Philliam_A)\
**Post date:** [January 25, 2010, 11:10pm UTC](https://www.ruby-forum.com/t/ruby-extension-problem/182277/1 "2010-01-25T23:10:53Z")

</div>

Hey guys,  
I am writing a ruby extension in C++ that exposes a function to ruby,  
and then opens a ruby interpreter that loads a file that can call the  
function.

I am following the Pragmatic Programmers guide to embedding and  
extending ruby. I have a function defined like this:

static VALUE Send (VALUE length, VALUE capMode, VALUE dev, VALUE pack)

then later to register it, there is this:

VALUE cTest;

void Init\_Send() {  
cTest = rb\_define\_module(“rpacket”);  
rb\_define\_module\_function(cTest, “Send”, Send, 4);  
}

However, when compiling, I get this error:

error C2664: ‘rb\_define\_module\_function’ : cannot convert parameter 3  
from ‘VALUE (\_\_cdecl \*)(VALUE,VALUE,VALUE,VALUE)’ to ‘VALUE (\_\_cdecl \*)  
(…)’

Anyone know why it’s failing?

---

<div class="post-metadata">

**Author:** ![Philliam\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@Philliam\_A](https://www.ruby-forum.com/u/Philliam_A)\
**Post date:** [January 25, 2010, 11:36pm UTC](https://www.ruby-forum.com/t/ruby-extension-problem/182277/2 "2010-01-25T23:36:39Z")

</div>

On Tue, Jan 26, 2010 at 07:10:15AM +0900, Philliam A. wrote:

> Hey guys,  
> I am writing a ruby extension in C++ that exposes a function to ruby,  
> and then opens a ruby interpreter that loads a file that can call the  
> function.
> 
> I am following the Pragmatic Programmers guide to embedding and  
> extending ruby. I have a function defined like this:
> 
> static VALUE Send (VALUE length, VALUE capMode, VALUE dev, VALUE pack)

This function needs to take a leading VALUE which holds a reference to  
the  
recipient of the call. Try this instead:

static VALUE Send (VALUE mod, VALUE length, VALUE capMode, VALUE dev,  
VALUE pack)

---

<div class="post-metadata">

**Author:** ![Philliam\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@Philliam\_A](https://www.ruby-forum.com/u/Philliam_A)\
**Post date:** [January 26, 2010, 12:15am UTC](https://www.ruby-forum.com/t/ruby-extension-problem/182277/3 "2010-01-26T00:15:52Z")

</div>

On Jan 25, 2:34 pm, Aaron P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> This function needs to take a leading VALUE which holds a reference to the  
> recipient of the call. Try this instead:
> 
> static VALUE Send (VALUE mod, VALUE length, VALUE capMode, VALUE dev, VALUE pack)
> 
> –  
> Aaron P.[http://tenderlovemaking.com/](http://tenderlovemaking.com/)

I still have a similar error:

1\>.\main.cpp(45) : error C2664: ‘rb\_define\_module\_function’ : cannot  
convert parameter 3 from ‘VALUE (\_\_cdecl \*)  
(VALUE,VALUE,VALUE,VALUE,VALUE)’ to ‘VALUE (\_\_cdecl \*)(…)’  
1\> None of the functions with this name in scope match the  
target type

Line 45 is the

rb\_define\_module\_function(cTest, “Send”, Send, 4);
