Skip to main content

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
However, only .NET bindings are officially maintained and tested.

Building

Prerequisites

  1. Rust toolchain (1.88.0 or later)
  2. Diplomat tool: cargo xtask ffi install
  3. .NET SDK (for .NET bindings)

Build Steps

This produces:
  • target/debug/libdevolutions_ironrdp.{so|dylib|dll} - Native library
  • ffi/dotnet/Devolutions.IronRdp/Generated/ - C# bindings

.NET API

Installation

Core Modules

The FFI is organized into the following modules:

Connection Establishment

ClientConnector

The ClientConnector 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 text
  • CF_DIB (8): Device-independent bitmap
  • CF_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 return Result<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.props
  • Devolutions.IronRdp.Build.iOS.props

Examples

Connect Example

A console application demonstrating basic RDP connection establishment.

Avalonia Example

A full GUI application using Avalonia framework with:
  • 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 &mut and take())
  • Objects are automatically freed when disposed

Consumed Values

Some operations consume their inputs:
Methods that consume values are clearly documented and will return 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 WriteBuf instances to reduce allocations
  • Batch input events: Use FastPathInputEventIterator to send multiple events at once

Diplomat Configuration

The .NET bindings are configured via dotnet-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
The NuGet package includes platform-specific native libraries that are automatically deployed.

Value Consumed Errors

If you see “value is consumed” errors:
  1. Check if you’ve called a consuming method
  2. Don’t reuse objects after consumption
  3. 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:

Future Development

Planned improvements:
  • JavaScript/TypeScript bindings via Diplomat
  • Python bindings
  • Additional platform support (Android, more .NET platforms)
  • Async API variants