# Ffi: Can't get dll to work

**URL:** <https://rubytalk.org/t/ffi-cant-get-dll-to-work/67016>\
**Category:** ruby-talk\
**Created:** [9 January 2013 10:34 UTC](https://rubytalk.org/t/ffi-cant-get-dll-to-work/67016 "2013-01-09T10:34:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [9 January 2013 10:34 UTC](https://rubytalk.org/t/ffi-cant-get-dll-to-work/67016/1 "2013-01-09T10:34:05Z")

</div>

Hi,

I want to use PICkit's dll (PICkitS.dll) from Ruby on Windows XP, but I  
doesn't succeed to get it done. I'd greatly appreciate any help.

I think, ffi would be usefull.

Documentation of PICkitS.dll says, for example:

Simple Function call:

PICkitS.Basic.Initialize\_PICkitSerial()

Returns: True if successful, False if not  
[...]

More complex Function call:

PICkitS.Basic.Send\_SPI\_Receive\_Cmd(byte  
p\_num\_bytes\_to\_read, ref byte[] p\_data\_array, bool  
p\_first\_cmd, bool p\_last\_cmd, ref string p\_script\_view)

Returns: True if successful, False if not  
[...]

I tried for example this:

require 'ffi'  
module PicKit  
&nbsp;&nbsp;extend FFI::Library  
&nbsp;&nbsp;ffi\_lib 'D:\e\Microchip\PICkit Serial Analyzer\PICkitS.dll'  
&nbsp;&nbsp;ffi\_convention :stdcall  
&nbsp;&nbsp;attach\_function :Initialize\_PICkitSerial, [], :void  
end

PicKit::Basic.Initialize\_PICkitSerial([:pointer, nil])

This returns the following error:

ruby18\_mingw/lib/ruby/gems/1.8/gems/ffi-1.3.0-x86-mingw32/lib/ffi/library.rb:251:in  
`attach\_function': Function 'Initialize\_PICkitSerial' not found in  
[D:\e\Microchip\PICkit Serial Analyzer\PICkitS.dll] (FFI::NotFoundError)

I've installed:  
ruby 1.8.7 (2009-06-12 patchlevel 174) [i386-mingw32]  
and  
ruby 1.9.3p327 (2012-11-10) [i386-mingw32]  
on  
Window XP

I do not know C.

Best regards,  
Axel

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
