A foreign function interface (FFI) is a mechanism for one language to interact with software written in another language.
Questions tagged [ffi]
1778 questions
0
votes
1 answer
CocoaPods error : Ignoring ffi-1.14.2 because its extensions are not built
After Firebase configuration, I try to run the simulator IOS 15.2 on iPhone 8 with visual Studio code with the command "run without debugging" but I get this error :
Launching lib/main.dart on iPhone 8 in debug mode... CocoaPods' output:
Error…

ismail
- 318
- 2
- 11
0
votes
1 answer
How to safely wrap win32's PSTR or PWSTR in an Option type (e.g. Option<&OsStr>)?
I am trying to create a safe wrapper around some Win32 APIs using Microsoft's windows crate like so:
use windows::{Win32::Foundation::*, Win32::System::Threading::*};
fn create_process(app_name: &std::ffi::OsStr) -> bool {
let mut startup_info:…

Lord BumbleBird
- 3
- 1
0
votes
0 answers
Is `Marshall.GetFunctionPointerForDelegate()` required?
I want to pass a callback from C# to native rust code. Online I saw those two methods:
Directly passing in a function that conforms delegate type.
Api.set_on_new_connection(OnNewConnection);
// ffi
[DllImport]
public static extern Result…

Timon Post
- 2,779
- 1
- 17
- 32
0
votes
0 answers
Long strings mangled for Idris to C++
I'm calling C++ from Idris. It's working fine, mostly, but while I can use short strings fine, long strings get mangled. Here's my code
// C++
extern "C" {
const char* foo() {
std::string res = "foo";
return res.c_str();
…

joel
- 6,359
- 2
- 30
- 55
0
votes
0 answers
How to build a library for rust plugins for an existing app?
I would like to write a library to make it easier to write DLL plugins for a non-rust program, with a C API/ABI, but I do not see how I could achieve that.
In my poc I have functions like
#[no_mangle] (repeated each time)
extern "C" fn init(*mut…

DaLynX
- 328
- 1
- 11
0
votes
2 answers
Is there a way to export functions in C static library?
i am testing some C code in Rust, but rust only links to C static libraries on windows.
The problem is that the exported C functions are only exported to a Dynamic Library, and not to a Static one, since I can't use dlls in rust, i can't really link…

Rafaelplayerxd YT
- 351
- 2
- 13
0
votes
1 answer
Pass mutable pointer to function without initializing it first
use std::ptr::{addr_of_mut, null_mut};
use libc::{CLOCK_MONOTONIC, timer_create, timer_delete, timer_t};
fn main() {
let mut timer1: timer_t = null_mut();
unsafe {
let r = timer_create(CLOCK_MONOTONIC, null_mut(),…

hdante
- 7,685
- 3
- 31
- 36
0
votes
1 answer
How to crash on internal bug and force totality
I'm ffi-ing to C and the function I call returns an int to mean gt, eq or lt. I want to crash on anything other than 1, 0 or -1 cos that should never happen. And I'd like Idris to consider 0, 1 and -1 to be exhaustive matches. I tried
prim__compare…

joel
- 6,359
- 2
- 30
- 55
0
votes
1 answer
Dart FFI bindings to ***struct: iterate over 'result'
I'm trying to write FFI bindings to a C library that has a function that uses ***Struct as one of its parameters:
typedef struct {
char *name;
char *value;
} StructType;
extern void theFunction(StructType ***list);
which should be called,…

Maarten Boekhold
- 867
- 11
- 21
0
votes
1 answer
How can I fill an uninitialized Rust vector using a C function?
I'm trying to call a C function that fills in a vector from Rust. Here is a complete minimal working example:
Cargo.toml
[package]
name = "so"
version = "0.1.0"
edition = "2021"
[build-dependencies]
cc = "1.0.72"
build.rs
fn main() {
…

wyoumans
- 350
- 1
- 3
- 10
0
votes
0 answers
How to Pass Variable from Shared Object (.so or .dll) to NodeJS?
It's working with functions by using node-ffi-napi. However, I couldn't find the way to pass variable from shared object (or DLL in Windows term) to NodeJS.
As example, here's my C code:
// mylibrary.h
extern int example;
// mylibrary.c
#include…

Thor-x86_128
- 157
- 18
0
votes
1 answer
Issue with cocoa pods on MacBook Air M1 chip, Big Sur OS v11.6.1
I'm an app developer, and I have been having a hell of a time trying to get set up on my new Mac. I'm working on an app that has dependencies that require cocoa pods, but I keep getting Error running pod install errors when launching it for testing…

ESM
- 175
- 10
0
votes
1 answer
Static linking in Dart FFI
I am writing a cli on Dart using a third-party library in the C language. I want to compile a single executable file. Is it possible? I linked the library dynamically using ffi. But is there a way to do statically, something like this ?

Aleksey Melikov
- 3
- 2
0
votes
0 answers
Can QCoreApplication::exec() be replaced with a while() loop?
I'm working on QML bindings for a programming language using QGuiApplication and QQmlApplicationEngine. I need a way to replace exec() with a while() loop so that I can still process events.
Basically, instead of
QGuiApplication app;
app.exec();
I…

Alex Shaw
- 163
- 1
- 7
0
votes
1 answer
How do I pass a Lua Table to/from a C function using cffi-lua
I'm using Lua 5.4.3 and not LuaJIT/FFI, but with cffi-lua, on Ubuntu 21.10
If the C function is
ffi.cdef [[
void dummy(int* ptr_form_lua, int size)
]]
and the Lua Table is
local mytable = {2,4,6,8} --as if an array of ints
How do I pass that…

jradxl
- 535
- 1
- 4
- 20