How to implement RVExtension function for DLA ArmA 3 in Rust?

I am trying to write a DLL extension for ArmA 3 and game documents :

The dll is expected to contain an entry point of the form _RVExtension @ 12 with the following C signature:

void __stdcall RVExtension(char *output, int outputSize, const char *function);

Part of the C ++ code example:

// ...

extern "C" {
    __declspec(dllexport) void __stdcall RVExtension(
        char *output,
        int outputSize,
        const char *function
    ); 
};

void __stdcall RVExtension(
    char *output,
    int outputSize,
    const char *function
) {
    outputSize -= 1;
    strncpy(output,function,outputSize);
}

The documents also have many examples in other languages, such as: C #, D and even Pascal , but this does not help me very much because I do not have a good understanding of their FFI = (.

I am stuck with the following Rust code:

#[no_mangle]
pub extern "stdcall" fn RVExtension(
    game_output: *mut c_char,
    output_size: c_int,
    game_input: *const c_char
) {
    // ...
}

But ArmA refuses to call him.

+4
source share
1 answer

@Shepmaster Dependency Walker, , . , _name@X, . RVExtension , ArmA _RVExtension@12.

, , . ~ 8 32- Rust nightly 1.8 (GNU ABI).

:

#![feature(libc)]
extern crate libc;

use libc::{strncpy, size_t};

use std::os::raw::c_char;
use std::ffi::{CString, CStr};
use std::str;

#[allow(non_snake_case)]
#[no_mangle]
/// copy the input to the output
pub extern "stdcall" fn _RVExtension(
    response_ptr: *mut c_char,
    response_size: size_t,
    request_ptr: *const c_char,
) {
    // get str from arma
    let utf8_arr: &[u8] = unsafe { CStr::from_ptr(request_ptr).to_bytes() };
    let request: &str = str::from_utf8(utf8_arr).unwrap();

    // send str to arma
    let response: *const c_char = CString::new(request).unwrap().as_ptr();
    unsafe { strncpy(response_ptr, response, response_size) };
}

:

#[export_name="_RVExtension"]
pub extern "stdcall" fn RVExtension(

Rust :

#[export_name="_RVExtension@12"]
pub extern "stdcall" fn RVExtension(

, , 1.8 (MSVC ABI) 32- VS 2015 @ . MSVC @12 .

@12, _RVExtension@12@12.


, ArmA - 32- , 64- DLL.

+5

All Articles