CINXE.COM

FFI - Perl Foreign Function Interface based on libffi - metacpan.org

<!DOCTYPE html> <html lang="en-US"> <head> <title>FFI - Perl Foreign Function Interface based on libffi - metacpan.org</title> <link rel="preload" as="fetch" href="/account/login_status" crossorigin="anonymous" /> <link href="/assets/style-XFEQ536G.css" rel="stylesheet" type="text/css"> <script src="/assets/main-WXBSEDQJ.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of FFI - MetaCPAN" href="/dist/FFI/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/FFI" /> <meta name="description" content="Perl Foreign Function Interface based on libffi" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <link rel="shortcut icon" href="/static/icons/favicon.ico"> <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/apple-touch-icon.png"> <link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN"> <script async src="https://perl-ads.perlhacks.com/perl-ads.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-E82Q2V8LVD"></script> <meta property="og:site_name" content="MetaCPAN" /> <meta name="twitter:site" content="@metacpan" /> <meta property="og:type" content="article" /> <meta name="twitter:card" content="summary" /> <meta property="og:url" content="https://metacpan.org/pod/FFI" /> <meta property="og:title" content="FFI" /> <meta property="og:description" content="Perl Foreign Function Interface based on libffi" /> <meta property="og:image" content="https://metacpan.org/static/images/dots.png" /> </head> <body> <nav class="navbar navbar-default" role="navigation"> <div class="header-logo-large hidden-xs"> <a href="/" tabindex="0"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#logo" /> </svg> </a> </div> <div class="header-logo-icon visible-xs"> <a href="/"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#dots" /> </svg> </a> </div> <ul class="nav navbar-nav menu-items hidden-xs hidden-sm"> <li><a href="/about">About</a></li> <li><a href="/about/sponsors">Sponsor</a></li> <li><a href="https://grep.metacpan.org/">grep::cpan</a></li> <li><a href="/recent">Recent</a></li> <li><a href="/about/faq">FAQ</a></li> <li><a href="/tools">Tools</a></li> <li><a href="https://fastapi.metacpan.org/">API</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <button type="button" class="searchbar-btn visible-xs visible-sm"> <i class="fa fa-search button-fa-icon"></i> </button> <form action="/search" class="searchbar-form visible-md visible-lg search-form form-horizontal"> <input type="hidden" name="size" id="metacpan_search-size" value="20"> <div class="form-group"> <div class="search-group"> <i class="fa fa-search"></i> <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value=""> </div> </div> </form> <li class="icon-slidepanel visible-xs visible-sm"> <button data-toggle="slidepanel" data-target=".slidepanel"> <span class="button-fa-icon"> <i class="fa fa-bars slidepanel-open"></i> <i class="fa fa-times slidepanel-close"></i> </span> </button> </li> <li class="dropdown login-dropdown show-logged-in"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li><a href="/account/identities">Identities</a></li> <li><a href="/account/profile">Profile</a></li> <li><a href="/account/favorite/list">Favorites</a></li> <li> <a href="#" type="button" class="logout-button"> Logout </a> </li> </ul> </li> <li class="dropdown login-dropdown show-logged-out"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon avatar-placeholder" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li> <a href="/login/github"> <i class="fab fa-github fa-fw"></i> GitHub </a> </li> <li> <a href="/login/twitter"> <i class="fab fa-twitter fa-fw"></i> Twitter </a> </li> <li> <a href="/login/google"> <i class="fab fa-google fa-fw"></i> Google </a> </li> </ul> </li> <li class="dropdown login-dropdown hide-logged-in hide-logged-out"> <button> <i class="fa fa-user button-fa-icon" aria-hidden="true"></i> </button> </li> </ul> </nav> <div class="page-content "> <div id="perl-ad-target" class="top-notify-banner perl-ad-target"> </div> <nav class="sidebar"> <div class="slidepanel"> <ul class="nav-list "> <li class="nav-header no-margin-top"> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of FFI was released."> <span class="relatize">13 Dec 2019 15:22:59 UTC</span> </div> </li> <li> Distribution: <a href="/dist/FFI">FFI</a> </li> <li> Module version: 1.15 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/FFI/source/lib/FFI.pm">Source</a> (<a href="/dist/FFI/source/lib/FFI.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/FFI/source/lib">Browse</a> (<a href="/dist/FFI/source/lib?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/FFI/changes">Changes</a> </li> <li> <a rel="noopener nofollow" class="nopopup" href="https://metacpan.org/pod/FFI">Homepage</a> </li> <li> <a class="nopopup" href="/dist/FFI/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/Perl5-FFI/FFI">Repository</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://github.com/Perl5-FFI/FFI/issues">Issues</a> (0) </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=FFI+1.15" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/F/FFI.html?oncpan=1&amp;distmat=1&amp;version=1.15&amp;grade=2" style="color: #090">331</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/F/FFI.html?oncpan=1&amp;distmat=1&amp;version=1.15&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/F/FFI.html?oncpan=1&amp;distmat=1&amp;version=1.15&amp;grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/PLICEASE/FFI-1.15">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on FFI who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)"> Bus factor: 2 </div> </li> <li> <a rel="noopener nofollow" href="http://cpancover.com/latest/FFI-1.15/index.html">79.75% Coverage </a> </li> <li> License: perl_5 </li> <li> Perl: v5.6.0 </li> <li class="chat-banner"> <div><a rel="noopener nofollow" target="_blank" href="https://kiwiirc.com/nextclient/#irc://irc.perl.org/#native?nick=mc-guest-?">Chat with us!</a></div> </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/FFI/activity.svg?res=month" /> <div class="comment">24 month</div> </div> </li> <li class="nav-header">Tools</li> <li> <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/P/PL/PLICEASE/FFI-1.15.tar.gz"> Download (<span itemprop="fileSize">21.21KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FPLICEASE%2FFFI-1.15%2Flib%2FFFI.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/FFI/permissions"> Permissions </a> </li> <li> <a href="/dist/FFI/releases.rss"> Subscribe to distribution </a> </li> <li> <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog"> Install Instructions </button> </li> <li> <form action="/search"> <input type="hidden" name="q" value="dist:FFI"> <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li> <form action="https://grep.metacpan.org/search"> <input type="hidden" name="qd" value="FFI"> <input type="hidden" name="source" value="metacpan"> <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li class="version-jump"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Jump to version</option> <option disabled value="/release/PLICEASE/FFI-1.15/view/lib/FFI.pm" >1.15 (PLICEASE on 2019-12-13)</option> <option value="/release/SCHWA/FFI-1.04-dll/view/lib/FFI.pm" >1.04-dll (SCHWA on 2009-09-17)</option> <option value="/release/GAAL/FFI-1.04/view/lib/FFI.pm" >1.04 (GAAL on 2008-09-06)</option> <option value="/release/GAAL/FFI-1.03/view/lib/FFI.pm" >1.03 (GAAL on 2007-12-26)</option> <option value="/release/GAAL/FFI-1.02/view/lib/FFI.pm" >1.02 (GAAL on 2007-02-07)</option> <option value="/release/PMOORE/FFI/view/lib/FFI.pm" > (PMOORE on 2000-10-31)</option> <option value="/release/PMOORE/FFI-1.00/view/lib/FFI.pm" >1.00 (PMOORE on 2000-10-31)</option> <option value="/release/PMOORE/FFI-0.01/view/lib/FFI.pm" >0.01 (PMOORE on 1999-10-01)</option> <optgroup label="BackPAN">' <option value="/release/PLICEASE/FFI-1.14/view/lib/FFI.pm" >1.14 (PLICEASE on 2019-02-10)</option> <option value="/release/PLICEASE/FFI-1.12/view/lib/FFI.pm" >1.12 (PLICEASE on 2018-06-01)</option> <option value="/release/PLICEASE/FFI-1.11/view/lib/FFI.pm" >1.11 (PLICEASE on 2018-05-29)</option> <option value="/release/PLICEASE/FFI-1.10/view/lib/FFI.pm" >1.10 (PLICEASE on 2017-03-23)</option> <option value="/release/PLICEASE/FFI-1.09/view/lib/FFI.pm" >1.09 (PLICEASE on 2015-08-02)</option> <option value="/release/PLICEASE/FFI-1.08/view/lib/FFI.pm" >1.08 (PLICEASE on 2015-06-23)</option> <option value="/release/PLICEASE/FFI-1.07/view/lib/FFI.pm" >1.07 (PLICEASE on 2015-03-02)</option> <option value="/release/PLICEASE/FFI-1.06/view/lib/FFI.pm" >1.06 (PLICEASE on 2015-03-01)</option> <option value="/release/PLICEASE/FFI-1.05/view/lib/FFI.pm" >1.05 (PLICEASE on 2015-03-01)</option> <option value="/release/DCMERTENS/FFI-1.04_01/view/lib/FFI.pm" >1.04_01 DEV (DCMERTENS on 2012-04-30)</option> </optgroup> </select> </li> <li class="version-diff"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Diff with version</option> <option disabled value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.15/lib/FFI.pm" >1.15 (PLICEASE on 2019-12-13)</option> <option value="/release/PLICEASE/FFI-1.15/diff/SCHWA/FFI-1.04-dll/lib/FFI.pm" >1.04-dll (SCHWA on 2009-09-17)</option> <option value="/release/PLICEASE/FFI-1.15/diff/GAAL/FFI-1.04/lib/FFI.pm" >1.04 (GAAL on 2008-09-06)</option> <option value="/release/PLICEASE/FFI-1.15/diff/GAAL/FFI-1.03/lib/FFI.pm" >1.03 (GAAL on 2007-12-26)</option> <option value="/release/PLICEASE/FFI-1.15/diff/GAAL/FFI-1.02/lib/FFI.pm" >1.02 (GAAL on 2007-02-07)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PMOORE/FFI/lib/FFI.pm" > (PMOORE on 2000-10-31)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PMOORE/FFI-1.00/lib/FFI.pm" >1.00 (PMOORE on 2000-10-31)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PMOORE/FFI-0.01/lib/FFI.pm" >0.01 (PMOORE on 1999-10-01)</option> <optgroup label="BackPAN">' <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.14/lib/FFI.pm" >1.14 (PLICEASE on 2019-02-10)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.12/lib/FFI.pm" >1.12 (PLICEASE on 2018-06-01)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.11/lib/FFI.pm" >1.11 (PLICEASE on 2018-05-29)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.10/lib/FFI.pm" >1.10 (PLICEASE on 2017-03-23)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.09/lib/FFI.pm" >1.09 (PLICEASE on 2015-08-02)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.08/lib/FFI.pm" >1.08 (PLICEASE on 2015-06-23)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.07/lib/FFI.pm" >1.07 (PLICEASE on 2015-03-02)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.06/lib/FFI.pm" >1.06 (PLICEASE on 2015-03-01)</option> <option value="/release/PLICEASE/FFI-1.15/diff/PLICEASE/FFI-1.05/lib/FFI.pm" >1.05 (PLICEASE on 2015-03-01)</option> <option value="/release/PLICEASE/FFI-1.15/diff/DCMERTENS/FFI-1.04_01/lib/FFI.pm" >1.04_01 DEV (DCMERTENS on 2012-04-30)</option> </optgroup> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><a href="/pod/FFI::Platypus" title="FFI::Platypus" class="ellipsis">FFI::Platypus</a></li> <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li> <li> <hr> </li> <li> <a href="/module/FFI/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=FFI">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=FFI">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/PLICEASE/FFI-1.15/view/lib/FFI.pm">This version</a> </li> <li> <a href="/pod/FFI">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/POTATOGIM"><img src="https://www.gravatar.com/avatar/82f1c6258702415af6e26187f1e36850?d=identicon&amp;s=20" title="POTATOGIM" alt="POTATOGIM"></a> <a class="display-all" href="/author/KES"><img src="https://www.gravatar.com/avatar/e8530f00b43b4f6a056f8ad4ee52ea47?d=identicon&amp;s=20" title="KES" alt="KES"></a> <a class="display-all" href="/author/KEEDI"><img src="https://www.gravatar.com/avatar/95f905a7a4ccc573c711e9d264c0fde8?d=identicon&amp;s=20" title="KEEDI" alt="KEEDI"></a> <a class="display-all" href="/author/ASHLEYW"><img src="https://www.gravatar.com/avatar/13c6f51a9d29a7e3e429269be383f72f?d=identicon&amp;s=20" title="ASHLEYW" alt="ASHLEYW"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/FFI/plussers">4 PAUSE users</a> </div> </div> </li> <li> <div> <button class="contributors-show-button btn-link">and 5 contributors</button> <div id="metacpan_contributors" class="slide-out slide-out-hidden"> <div> <ul> <li class="contributor" data-contrib-email="avorobey@pobox.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Anatoly Vorobey </li> <li class="contributor" data-cpan-author="GAAL" data-contrib-email="gaal@forum2.org" > <a href="/author/GAAL" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/f9044707405d78e4baf0fc681aaa0dc8?d=identicon&amp;s=20" /> Gaal Yahas </a> </li> <li class="contributor" data-contrib-email="mcharity@vendian.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Mitchell Charity </li> <li class="contributor" data-contrib-email="gustav@morpheus.demon.co.uk" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Paul Moore </li> <li class="contributor" data-cpan-author="RURBAN" data-contrib-email="RURBAN@cpan.org" > <a href="/author/RURBAN" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/87a08c1a47ade883c793d1f94422a78a?d=identicon&amp;s=20" /> Reini Urban &lt; </a> </li> </ul> </div> </div> </div> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/PLICEASE" class="author-name">Graham Ollis 馃敟馃悏</a> </span> <span>&nbsp;/&nbsp;</span> <div class="release dist-release status-latest maturity-released"> <span class="dropdown"><b class="caret"></b></span> <select class="select-navigator "> <option selected value="/release/PLICEASE/FFI-1.15/view/lib/FFI.pm" >1.15 (PLICEASE on 2019-12-13)</option> <option value="/release/SCHWA/FFI-1.04-dll/view/lib/FFI.pm" >1.04-dll (SCHWA on 2009-09-17)</option> <option value="/release/GAAL/FFI-1.04/view/lib/FFI.pm" >1.04 (GAAL on 2008-09-06)</option> <option value="/release/GAAL/FFI-1.03/view/lib/FFI.pm" >1.03 (GAAL on 2007-12-26)</option> <option value="/release/GAAL/FFI-1.02/view/lib/FFI.pm" >1.02 (GAAL on 2007-02-07)</option> <option value="/release/PMOORE/FFI/view/lib/FFI.pm" > (PMOORE on 2000-10-31)</option> <option value="/release/PMOORE/FFI-1.00/view/lib/FFI.pm" >1.00 (PMOORE on 2000-10-31)</option> <option value="/release/PMOORE/FFI-0.01/view/lib/FFI.pm" >0.01 (PMOORE on 1999-10-01)</option> <optgroup label="BackPAN">' <option value="/release/PLICEASE/FFI-1.14/view/lib/FFI.pm" >1.14 (PLICEASE on 2019-02-10)</option> <option value="/release/PLICEASE/FFI-1.12/view/lib/FFI.pm" >1.12 (PLICEASE on 2018-06-01)</option> <option value="/release/PLICEASE/FFI-1.11/view/lib/FFI.pm" >1.11 (PLICEASE on 2018-05-29)</option> <option value="/release/PLICEASE/FFI-1.10/view/lib/FFI.pm" >1.10 (PLICEASE on 2017-03-23)</option> <option value="/release/PLICEASE/FFI-1.09/view/lib/FFI.pm" >1.09 (PLICEASE on 2015-08-02)</option> <option value="/release/PLICEASE/FFI-1.08/view/lib/FFI.pm" >1.08 (PLICEASE on 2015-06-23)</option> <option value="/release/PLICEASE/FFI-1.07/view/lib/FFI.pm" >1.07 (PLICEASE on 2015-03-02)</option> <option value="/release/PLICEASE/FFI-1.06/view/lib/FFI.pm" >1.06 (PLICEASE on 2015-03-01)</option> <option value="/release/PLICEASE/FFI-1.05/view/lib/FFI.pm" >1.05 (PLICEASE on 2015-03-01)</option> <option value="/release/DCMERTENS/FFI-1.04_01/view/lib/FFI.pm" >1.04_01 DEV (DCMERTENS on 2012-04-30)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/FFI">FFI-1.15</a> </div> <span class="river-gauge-gauge"> <svg width="24px" height="15px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <title> River stage zero &#10; No dependents </title> <rect x="0" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="5" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="10" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="15" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="20" y="0" width="4" height="15" fill="#e4e2e2" /> </g> </svg> </span> <div id="FFI-fav" class="show-logged-in"> <form action="/account/favorite/add" style="display: inline" method="POST"> <input type="hidden" name="remove" value="0"> <input type="hidden" name="release" value="FFI-1.15"> <input type="hidden" name="author" value="PLICEASE"> <input type="hidden" name="distribution" value="FFI"> <button type="submit" class="favorite highlight"><span>4</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>4</span> ++</button> </div> / <span>FFI</span> </div> </div> <main class="content"> <nav class="toc"> <div class="toc-header"><strong>Contents</strong></div> <ul> <li><a href="#NAME">NAME</a></li> <li><a href="#VERSION">VERSION</a></li> <li><a href="#SYNOPSIS">SYNOPSIS</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a></li> <li><a href="#FUNCTIONS">FUNCTIONS</a> <ul> <li><a href="#call">call</a></li> <li><a href="#callback">callback</a></li> </ul> </li> <li><a href="#FUNCTION-SIGNATURES">FUNCTION SIGNATURES</a></li> <li><a href="#SUPPORT">SUPPORT</a></li> <li><a href="#SEE-ALSO">SEE ALSO</a></li> <li><a href="#AUTHOR">AUTHOR</a></li> <li><a href="#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>FFI - Perl Foreign Function Interface based on libffi</p> <h1 id="VERSION">VERSION</h1> <p>version 1.15</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code># for a more portable interface see FFI::Library $clib_file = ($^O eq &quot;MSWin32&quot;) ? &quot;MSVCRT40.DLL&quot; : &quot;-lc&quot;; $clib = DynaLoader::dl_findfile($clib_file); $strlen = DynaLoader::dl_find_symbol($clib, &quot;strlen&quot;); $n = FFI::call($strlen, &quot;cIp&quot;, $my_string); DynaLoader::dl_free_file($clib);</code></pre> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p><b>NOTE</b>: Newer and better maintained FFI modules such as <a href="/pod/FFI::Platypus">FFI::Platypus</a> provide more functionality and so it is strongly recommend that you use one of them for new projects and even consider migrating to one of them for existing projects.</p> <p>This module provides a low-level foreign function interface to Perl. It allows the calling of any function for which the user can supply an address and calling signature. Furthermore, it provides a method of encapsulating Perl subroutines as callback functions whose addresses can be passed to C code.</p> <h1 id="FUNCTIONS">FUNCTIONS</h1> <h2 id="call">call</h2> <pre><code>my $ret = FFI::call($address, $signature, @arguments);</code></pre> <p>Call the function at the given <code>$address</code> with the given <code>$signature</code>&gt; (see below) and the given <code>@arguments</code>.</p> <h2 id="callback">callback</h2> <pre><code>my $address = FFI::callback($signature, \&amp;subref);</code></pre> <p>Creates a c callback that will call a Perl subref.</p> <h1 id="FUNCTION-SIGNATURES"><a id="FUNCTION"></a>FUNCTION SIGNATURES</h1> <p>Function interfaces are defined by <i>signatures</i>. A function&#39;s signature is a string which specifies the function&#39;s return type, argument types and calling convention. The first character of the string is the function&#39;s calling convention. This is one of</p> <pre><code>s The standard calling convention for dynamically linked functions c The calling convention used by C functions</code></pre> <p>Note that on many platforms, these two calling conventions may be identical. On the Windows platform, the <code>s</code> code corresponds to the <code>stdcall</code> calling convention, which is used for most dynamic link libraries. The <code>c</code> code corresponds to the <code>cdecl</code> calling convention, which is used for C functions, such as those in the C runtime library.</p> <p>The remaining characters of the string are the return type of the function, followed by the argument types, in left-to-right order. Valid values are based on the codes used for the <a href="/pod/pack">pack</a> function, namely</p> <pre><code>c A signed char value. C An unsigned char value. s A signed short value. S An unsigned short value. i A signed integer value. I An unsigned integer value. l A signed long value. L An unsigned long value. f A single-precision float. d A double-precision float. p A pointer to a Perl scalar. o A opaque pointer, ie, an address. v No value (only valid as a return type).</code></pre> <p>Note that all of the above codes refer to &quot;native&quot; format values.</p> <p>The <code>p</code> code as an argument type simply passes the address of the Perl value&#39;s memory to the foreign function. It is the caller&#39;s responsibility to be sure that the called function does not overwrite memory outside that allocated by Perl.</p> <p>The <code>p</code> code as a return type treats the returned value as a null-terminated string, and passes it back to Perl as such. There is currently no support for functions which return pointers to structures, or to other blocks of memory which do not contain strings, nor for functions which return memory which the caller must free.</p> <p>To pass pointers to strings, use the <code>p</code> code. Perl ensures that strings are null-terminated for you. To pass pointers to structures, use <a href="/pod/pack">pack</a>. To pass an arbitrary block of memory, use something like the following:</p> <pre><code>$buf = &#39; &#39; x 100; # Use $buf via a &#39;p&#39; parameter as a 100-byte memory block</code></pre> <p>At the present time, there is no direct support for passing pointers to &#39;native&#39; types (like int). To work around this, use <code>$buf = pack(&#39;i&#39;, 12);</code> to put an integer into a block of memory, then use the <code>p</code> pointer type, and obtain any returned value using <code>$n = unpack(&#39;i&#39;, $buf);</code> In the future, better support may be added (but remember that this is intended as a low-level interface!)</p> <h1 id="SUPPORT">SUPPORT</h1> <p>Please open any support tickets with this project&#39;s GitHub repository here:</p> <p><a href="https://github.com/Perl5-FFI/FFI/issues">https://github.com/Perl5-FFI/FFI/issues</a></p> <h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1> <dl> <dt id="FFI::Library"><a id="FFI"></a><a href="/pod/FFI::Library">FFI::Library</a></dt> <dd> <p>Higher level interface to libraries using this module.</p> </dd> <dt id="FFI::CheckLib"><a id="FFI1"></a><a href="/pod/FFI::CheckLib">FFI::CheckLib</a></dt> <dd> <p>Portable functions for finding libraries.</p> </dd> <dt id="FFI::Platypus"><a id="FFI2"></a><a href="/pod/FFI::Platypus">FFI::Platypus</a></dt> <dd> <p>Platypus is another FFI interface based on libffi. It has a more extensive feature set, and libffi has a less restrictive license.</p> </dd> </dl> <h1 id="AUTHOR">AUTHOR</h1> <p>Original author: Paul Moore &lt;gustav@morpheus.demon.co.uk&gt;</p> <p>Current maintainer: Graham Ollis &lt;plicease@cpan.org&gt;</p> <p>Contributors:</p> <p>Anatoly Vorobey &lt;avorobey@pobox.com&gt;</p> <p>Gaal Yahas &lt;gaal@forum2.org&gt;</p> <p>Mitchell Charity &lt;mcharity@vendian.org&gt;</p> <p>Reini Urban &lt;&lt;RURBAN@cpan.org&gt;</p> <h1 id="COPYRIGHT-AND-LICENSE"><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1> <p>This software is copyright (c) 2016-2018 by Graham Ollis.</p> <p>This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.</p></div> <div id="metacpan_install-instructions-dialog" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <h4 class="modal-title">Module Install Instructions</h4> </div> <div class="modal-body"> <p>To install FFI, copy and paste the appropriate command in to your terminal.</p> <p><a href="/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p> <pre><code>cpanm FFI</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install FFI</code></pre> <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> </main> <div class="content-pagination"> </div> </div> <footer class="footer"> <div class="footer-container"> <div class="footer-social"> <div class="footer-link footer-logo"> <a href="/"> <img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" /> </a> </div> <a class="footer-social-link" href="https://github.com/metacpan"> <i class="fab fa-github-square"></i> </a> <a class="footer-social-link" href="https://fosstodon.org/@metacpan"> <i class="fab fa-mastodon"></i> </a> </div> <div class="footer-links"> <div class="footer-link"> <a href="/about">About</a> </div> <div class="footer-link"> <a href="/about/sponsors">Sponsor</a> </div> <div class="footer-link"> <a href="https://grep.metacpan.org">grep::cpan</a> </div> <div class="footer-link"> <a href="/recent">Recent</a> </div> <div class="footer-link"> <a href="/about/faq">FAQ</a> </div> <div class="footer-link"> <a href="/tools">Tools</a> </div> <div class="footer-link"> <a href="https://fastapi.metacpan.org/">API</a> </div> <div class="footer-link"> <a href="https://www.perl.org/">Perl.org</a> </div> </div> <div class="footer-sponsors"> <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener"> <img class="footer-sponsor-bytemark" src="/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener"> <img class="footer-sponsor-liquidweb" src="/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener"> <img class="footer-sponsor-deriv" src="/static/images/sponsors/deriv.svg" alt="Deriv logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener"> <img class="footer-sponsor-geocode" src="/static/images/sponsors/geocodelogo.svg" alt="Geocode logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener"> <img class="footer-sponsor-fastly" src="/static/images/sponsors/fastly_logo.svg" alt="Fastly logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener"> <img class="footer-sponsor-opencage" src="/static/images/sponsors/open-cage.svg" alt="OpenCage logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://www.elastic.co/" rel="noopener"> <img class="footer-sponsor-elastic" src="/static/images/sponsors/elastic.svg" alt="Elastic logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://route4me.com/" rel="noopener"> <img class="footer-sponsor-route4me" src="/static/images/sponsors/route4me.png" alt="Route4Me logo"> </a> </div> </div> </footer> <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Keyboard Shortcuts</h4> </div> <div class="modal-body row"> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Global</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>s</kbd> </td> <td>Focus search bar</td> </tr> <tr> <td class="keys"> <kbd>?</kbd> </td> <td>Bring up this help dialog</td> </tr> </tbody> </table> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>GitHub</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>p</kbd> </td> <td>Go to pull requests</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>go to github issues (only if github is preferred repository)</td> </tr> </tbody> </table> </div> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>POD</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>a</kbd> </td> <td>Go to author</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>c</kbd> </td> <td>Go to changes</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>Go to issues</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>d</kbd> </td> <td>Go to dist</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>r</kbd> </td> <td>Go to repository/SCM</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>s</kbd> </td> <td>Go to source</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>b</kbd> </td> <td>Go to file browse</td> </tr> </tbody> </table> </div> <div class="col-md-12"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Search terms</th> </tr> </thead> <tbody> <tr> <td><em>module:</em> (e.g. <a href="/search?q=module%3APlugin">module:Plugin</a>)</td> </tr> <tr> <td><em>distribution:</em> (e.g. <a href="/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td> </tr> <tr> <td><em>author:</em> (e.g. <a href="/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td> </tr> <tr> <td><em>version:</em> (e.g. <a href="/search?q=version%3A1.00">version:1.00</a>)</td> </tr> </tbody> </table> </div> </div> <div class="modal-footer"></div> </div> </div> </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10