IronRDP FFI
Foreign Function Interface (FFI) bindings for IronRDP, built using Diplomat. These bindings enable IronRDP usage from other programming languages.Overview
The IronRDP FFI provides a C-compatible API layer that can be consumed by various programming languages. Currently, .NET is the officially supported target platform with full bindings and examples. Source:ffi/
Supported Platforms
.NET (Official)
- Namespace:
Devolutions.IronRdp - Package: Available as NuGet package
- Platforms: Windows, macOS, Linux, iOS
- Language: C#
Other Languages
The Diplomat-based FFI can theoretically support:- C/C++
- JavaScript (via WebAssembly)
- Other languages with C interop
Building
Prerequisites
- Rust toolchain (1.88.0 or later)
- Diplomat tool:
cargo xtask ffi install - .NET SDK (for .NET bindings)
Build Steps
target/debug/libdevolutions_ironrdp.{so|dylib|dll}- Native libraryffi/dotnet/Devolutions.IronRdp/Generated/- C# bindings
.NET API
Installation
Core Modules
The FFI is organized into the following modules:| Module | Description |
|---|---|
connector | Connection establishment and protocol negotiation |
session | Active RDP session management |
input | Keyboard and mouse input handling |
graphics | Graphics rendering and pointer handling |
clipboard | Clipboard redirection (CLIPRDR) |
pdu | Protocol Data Unit encoding/decoding |
error | Error types and handling |
utils | Utility types and helpers |
dvc | Dynamic Virtual Channel support |
svc | Static Virtual Channel support |
rdcleanpath | RDCleanPath protocol support |
credssp | CredSSP/NLA authentication |
Connection Establishment
ClientConnector
TheClientConnector class manages the RDP connection sequence.
Config
Connection configuration parameters.Session Management
ActiveStage
Represents an active RDP session after connection is established.FastPath Input
Send keyboard and mouse input to the remote session.Graphics and Rendering
DecodedImage
Represents the decoded RDP framebuffer.DecodedPointer
Represents a cursor/pointer bitmap.Clipboard Redirection
Cliprdr
Manages clipboard synchronization between local and remote sessions.Clipboard Formats
Standard clipboard format IDs:CF_TEXT(1): Plain text (ANSI)CF_UNICODETEXT(13): Unicode textCF_DIB(8): Device-independent bitmapCF_DIBV5(17): DIB with color space- Custom formats: Use registered format IDs (> 0xC000)
Dynamic Virtual Channels
Display Control
Enable dynamic resolution changes.DVC Pipe Proxy
Proxy DVC traffic to named pipes (Windows).Error Handling
IronRdpError
All FFI methods returnResult<T, IronRdpError> which throws exceptions in .NET.
Error Kinds
PDU Handling
Action and WriteBuf
Low-level PDU processing.PduHint
Used for frame detection in raw byte streams.Utilities
Common Types
Platform-Specific Features
Windows Clipboard
Native Windows clipboard integration.iOS Support
The NuGet package includes iOS bindings with platform-specific properties:Devolutions.IronRdp.iOS.propsDevolutions.IronRdp.Build.iOS.props
Examples
Connect Example
Avalonia Example
- RDP session rendering
- Input handling
- Clipboard integration
- Resize support
Memory Management
Ownership
The FFI uses Rust’s ownership model:- Most objects are returned as
Box<T>(owned pointers) - Some objects are consumed by methods (marked with
&mutandtake()) - Objects are automatically freed when disposed
Consumed Values
Some operations consume their inputs:Consumed errors if called on already-consumed objects.
Thread Safety
The FFI is not thread-safe by default. All operations on a given RDP session must be performed from a single thread. For multi-threaded scenarios, implement your own synchronization.Performance Considerations
- Zero-copy where possible: The FFI minimizes data copying using byte slices
- Preallocate buffers: Reuse
WriteBufinstances to reduce allocations - Batch input events: Use
FastPathInputEventIteratorto send multiple events at once
Diplomat Configuration
The .NET bindings are configured viadotnet-interop-conf.toml:
Troubleshooting
Library Not Found
Ensure the native library is in the correct location:- Windows:
DevolutionsIronRdp.dll - macOS:
libDevolutionsIronRdp.dylib - Linux:
libDevolutionsIronRdp.so
Value Consumed Errors
If you see “value is consumed” errors:- Check if you’ve called a consuming method
- Don’t reuse objects after consumption
- Some methods like
Step()are non-consuming and can be called multiple times
IncorrectEnumType Errors
These occur when calling variant-specific methods on enum-like types:Related Documentation
- Diplomat: FFI generation tool
- IronRDP Architecture: Overall project structure
- ironrdp-web: WebAssembly bindings
Future Development
Planned improvements:- JavaScript/TypeScript bindings via Diplomat
- Python bindings
- Additional platform support (Android, more .NET platforms)
- Async API variants

