< 返回版块

c5soft 发表于 2022-03-17 10:34

Tags:powerbuilder,pb

直接上源代码:lib.rs

/// PowerBuilder 9 callable DLL example
/// Build with: cargo b --release --target i686-pc-windows-msvc
/// PB declare:  public function ulong copy_str(string source,ref string destination) library "hello.dll" alias for "copy_str"

use std::{ffi::CStr, os::raw::c_char, ptr::copy_nonoverlapping};
#[no_mangle]
pub unsafe extern "system" fn copy_str(src: *const c_char, dst: *mut c_char) -> u32 {
    let len = CStr::from_ptr(src).to_bytes().len();
    copy_nonoverlapping(src, dst, len + 1);
    len as u32
}

配置文件cargo.toml

[package]
name = "hello"
version = "0.1.0"

[lib]
crate-type = ["dylib"]

PowerBuilder调用声明:

public function ulong copy_str(string source,ref string destination) library "hello.dll" alias for "copy_str"

评论区

写评论
作者 c5soft 2022-03-18 08:05

PB9是32位的,ULong=u32

langzi.me 2022-03-17 18:17

ulong, 最少不得是u64?

1 共 2 条评论, 1 页