# Help On Ruby Integration With C

**URL:** <https://www.ruby-forum.com/t/help-on-ruby-integration-with-c/166245>\
**Category:** Ruby\
**Created:** [April 23, 2009, 6:09am UTC](https://www.ruby-forum.com/t/help-on-ruby-integration-with-c/166245 "2009-04-23T06:09:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 23, 2009, 6:09am UTC](https://www.ruby-forum.com/t/help-on-ruby-integration-with-c/166245/1 "2009-04-23T06:09:49Z")

</div>

Hi…

I m using ruby 1.8.6 on Windows…

I m extending Ruby with C.

that is i want to load a DLL into Ruby…

but Ruby fails load my Dll…

i use visual [studio.net](http://studio.net) command Prompt.

I integrate my dll namely prov.dll into C program namely pro1.c

afterthat i call those c functions through ruby .

D:\ruby\_extend\pronmake\>irb  
irb(main):001:0\> require ‘pro1’  
=\> true  
irb(main):002:0\> include Pro  
=\> Object  
irb(main):003:0\> Pro::load  
=\> false  
irb(main):004:0\>

i get only false…

dll fails to load through ruby…

how can i get the stacktrace ?

Any Advices…

Pls help me out

Thanks

below is my pro1.c code

#include “windows.h”

#include “ruby.h”

#include “pro.h”

#define \_D(string) {OutputDebugString(string);}

VALUE Pro;  
HINSTANCE hlibrary;

void \_textline(const char _s, int len)  
//_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{  
\_D(s);  
}

static VALUE p\_load(VALUE self )  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{

```
   return pro_load();

```

}

static VALUE p\_init(VALUE self)  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{  
\_D(“-\> init”);

```
     pro_set_textline_callback(_textline);

```

pro\_renderInit();

}

static VALUE p\_parse(VALUE self, VALUE string\_to\_parse)  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{

\_D(StringValuePtr(string\_to\_parse));  
return pro\_parse(StringValuePtr(string\_to\_parse));

}

void proeventcallback(proRenderEventType type, proRenderEventData data)  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{  
switch(type){  
case proRenderEventDone:  
\_D(“-\> cleanup”);  
pro\_renderCleanUp();  
//if (vWindow)  
//{  
// SendMessage((HWND)NUM2INT(vWindow), WM\_USER+2, 0, 0);  
//}  
}  
}

static VALUE pro\_render( VALUE self )  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{

```
_D("-> render");

```

pro\_set\_renderevent\_callback(proeventcallback);  
SetThreadPriority(GetCurrentThread(),THREAD\_PRIORITY\_ABOVE\_NORMAL);  
pro\_render(PRO\_RENDERASYNC);  
return Qtrue;  
}

void Init\_pro1()  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{

```
pro = rb_define_module( "Pro" );
rb_define_method(Pro, "load", p_load, 0);
rb_define_method( Pro, "init_engine", p_init, 0 );
rb_define_method(Pro, "parse", p_parse, 1);
rb_define_method(Pro, "render", pr_render, 0);

```

}
