Boscop / rusty-dll

Template project for creating Windows shared libraries (.dll)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rusty-dll

Template project for creating Windows shared libraries (.dll)

Quick start

You can either install cargo-generate tool with cargo install cargo-generate or clone this repository.

# Using `cargo-generate` tool
cargo generate https://github.com/sy1ntexx/rusty-dll

# Or clone the project itself
git clone https://github.com/sy1ntexx/rusty-dll

Don't forget to rename package to your project name in Cargo.toml

build/ folder contains batch scripts to quickly build your packet for x64 or x86 architecture.

x64 or x86

By default, cargo will compile for x64 bit architecture because of .cargo/config. If you want to target x86 you need to either change the target in configuration file, or take a use of handy scripts in the build folder.

Usage

Write the code you want in main_thread function.

#[no_mangle]
unsafe extern "C" fn DllMain(
    hinst_dll: usize,
    fdw_reason: u32,
    _lp_reserved: usize) -> i32
{
    match fdw_reason {
        1 => {
            std::thread::spawn(move || {
                unsafe { main_thread(hinst_dll) }
            });
        }
        _ => { return FALSE; }
    }
    1
}

unsafe extern "system" fn main_thread(lp_thread_parameter: usize) -> u32 {
    // AllocConsole();
    println!("Hello from #RustLang!");

    // Put your code here

    // FreeConsole();
    FreeLibraryAndExitThread(lp_thread_parameter as _, 0);
    0
}

Output

After successfull build, you can find your dll in target/TARGET_NAME/[debug/release]/

About

Template project for creating Windows shared libraries (.dll)


Languages

Language:Rust 69.9%Language:Batchfile 30.1%