B
B
C++ / C#

Using rust from cpp?

There is a dll on rust.
How to use function from it in cpp?
lib.rs

pub extern fn lt() {
    println!("Hello from the library!");
}

compiles cargo to rlib.dll
load.cpp
#include <windows.h>
#include <iostream>

using namespace std;

typedef void (__stdcall *f_lt)();

int main()
{
    HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\Users\\acer\\desktop\\c\\rlib.dll");
    if (!hGetProcIDDLL) {
    	std::cout << "could not load the dynamic library" << std::endl;
        return 1;
      }else{
      	std::cout << "success load the dynamic library" << std::endl;
      	f_lt lt = (f_lt)GetProcAddress(hGetProcIDDLL, "lt");
      	lt();
      }
}

the success of the library loading is displayed. but when there is a function call from it hangs.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question