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
0 answers
FFIing a C# char[][] into Rust
I'm trying to pass a char[][] to Rust, which then needs to decode it back to a String.
I've tried a few approaches:
Using Marshal to copy each array with a header of the array length, then reading it back in Rust.
I did this using…

Big_Bad_E
- 947
- 1
- 12
- 23
0
votes
0 answers
How to call shared library in darts with ffi
i tried call cpp code in dart but failed
import 'dart:ffi' as ffi;
import 'package:ffi/ffi.dart' as pkgffi;
void main(List arguments) {
try {
ffi.DynamicLibrary dynamicLibrary = ffi.DynamicLibrary.open("./lib.so");
var res =…

noobdev
- 95
- 1
- 6
0
votes
1 answer
Is there a safe alternative to CString::new() which does not require an unwrap?
I have some code in an FFI module which converts Rust strings to CStrings to be sent back to the caller.
I'm finding that the calling conventions for CString::new() to be difficult to use. Specifically:
This function will return an error if the…

pnadeau
- 427
- 5
- 8
0
votes
1 answer
How to call c++ methods from rust?
I would like to call the c++ methods from rust. I heard I need to create vtables(VMTs), but how can I do that? How is that different from what I did?
C++:
struct numbers {
int addnums(int a, int b) {
return a + b;
}
};
struct…
0
votes
0 answers
How can I Use DLL in Flutter with ffi?
I want to call c++ function using dll in flutter.
It's dll fuction Header.
It worked well when I called dll on mfc.
The name of DLL is "DllFont.dll".
#pragma once
#ifdef CREATEDLL_EXPORTS
#define FONTDLL_API __declspec(dllexport)
#else
#define…

JINMANXI
- 1
- 2
0
votes
0 answers
Integrating un4seen BASS with Flutter using FFI and getting symbol error
I'm trying to integrate the BASS audio library from un4seen Developments with Flutter, Google's cross-platform app development environment. I've started a Flutter plugin that can be found here: https://github.com/JimTompkins/flutter_bass. It uses…

JimTompkins
- 1
- 1
0
votes
1 answer
Strange error passing data from Rust to Java using ffi
I am writing some Rust code that uses a Rust library that doesn't seem to have a corresponding Java library (didcomm-rs).
Based on examples I've found, to pass String values between Rust and Java, I can use String in Java, and *const c_char in…

Quintonn
- 770
- 8
- 29
0
votes
0 answers
C# cast address to generic function signature
With C# 9 I can cast an address I get from a shared library to a function pointer and invoke it directly. This proved to be significantly more performant than mono's icalls or p/invoke and also less restrictive than the latter.
Now I have more than…

lsbehe
- 1
0
votes
0 answers
Different Target for Deref and DerefMut
I am trying to create a wrapper type around a cxx::UniquePtr.
I want to implement struct B(UniquePtr) with
Deref> for B
but also
DerefMut> for B {}
Is this a terrible idea or even possible? The whole…
0
votes
1 answer
How to use .a file for iOS with Flutter FFI?
I have a rust project. Compiling it to .so for android, I'm able to run it with Android. I have also generated .a file for iOS and used instructions for this answer but it's throwing following error: Semantic Issue (Xcode): Use of undeclared…

Mohit Singh
- 323
- 4
- 13
0
votes
1 answer
using C function that takes pointer to C struct typedef in Rust
I'm trying to use bindings generated for cuBLAS using bindgen. Here's what my code looks like:
mod tests {
use super::*;
#[test]
pub fn alpha () {
let mut handle: cublasHandle_t;
let mut stat: cublasStatus_t;
let…

Rylan Yancey
- 45
- 8
0
votes
0 answers
array of struct from c to dart using ffi flutter
I am trying to get array of 4 x int data using struct from c to dart via ffi.The code is compiling fine but the value i got in dart are garbage value that means i am goofing up in allocating memory.
And i am not sure which method to use for passing…

Ayush Yadav
- 376
- 2
- 11
0
votes
2 answers
Rust & FFI lib share string & free from both
I have a library that is used through its rust interface by rust programs, as well as through C/C++ programs through generated cbindgen bindings, so I implemented a free function to free the string once the ffi function has used the string. However…

t348575
- 674
- 8
- 19
0
votes
1 answer
Flutter ffigen and libtorrent
I am trying to generate bindings for libtorrent using ffigen.
The output of dart run ffigen --config ffigen.yaml is something like this
Input Headers: [src2/include/libtorrent/libtorrent.hpp]
[SEVERE] : Header src2/include/libtorrent/libtorrent.hpp:…

Davenchy
- 47
- 6
0
votes
1 answer
Problems implementing a wrapper-program for the camera remote sdk by sony
so... I am trying to create a wrapper program for the new Sony Camera Remote SDK listed on their website.
I was able to get a few functions to work. See below:
import ctypes
from ctypes import *
from sys import platform
shared_lib_path =…

JustKilian
- 1
- 2