Я пишу драйвер и решил импортировать NtGdiBitBlt и вызвать ее следующим способом
extern crate winapi;
use core::ffi::c_void;
extern "C" {
pub fn NtGdiBitBlt(
hdcDest: *mut c_void,
xDest: i32,
yDest: i32,
cxDest: i32,
cyDest: i32,
hdcSrc: *mut c_void,
xSrc: i32,
ySrc: i32,
rop: u32,
brush: *mut c_void,
xBrush: i32,
yBrush: i32,
) -> i32;
}
pub fn kernel_draw_example() {
unsafe {
let hdc_dest: *mut c_void = 0 as *mut c_void; // Fill in with actual DC handle
let hdc_src: *mut c_void = 0 as *mut c_void; // Fill in with actual DC handle
// Example call to NtGdiBitBlt
let result = NtGdiBitBlt(
hdc_dest, // Destination DC
0, // X position
0, // Y position
100, // Width
100, // Height
hdc_src, // Source DC (can be null if not needed)
0, // Source X
0, // Source Y
0x00CC0020, // ROP code (SRCCOPY, for example)
core::ptr::null_mut(), // Brush (optional)
0, // Brush X
0, // Brush Y
);
if result == 0 {
// Handle failure
}
}
}
Все компилируется если ее не вызывать, но при вызове вылезает ошибка error: linking with `link.exe` failed: exit code: 1120
Подробнее:
error: linking with `link.exe` failed: exit code: 1120
|
= note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.39.33519\\bin\\HostX64\\x64\\link.exe" "/DEF:C:\\Users\\zen\\AppData\\Local\\Temp\\rustc8h577g\\lib.def" "/NOLOGO" "/NOLOGO" "/NXCOMPAT" "/NODEFAULTLIB" "/SUBSYSTEM:NATIVE" "/DRIVER" "/DYNAMICBASE" "/INCREMENTAL:NO" "/MANIFEST:NO" "/PDBALTPATH:none" "C:\\Users\\zen\\AppData\\Local\\Temp\\rustc8h577g\\symbols.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.027tjrpvaotouv9o326cp5szl.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.1ffunq52xkcv1t06gqo36alnq.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.2f18hi9o0x3799ck4eum64d7v.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.411web2gavr3uuk8d07evcyv3.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.5pfk2lokzko85zoles7pisn0h.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.64jz2wh8eo2ok9ushtsz8rhh6.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.8r2v2xyjmxk7wk23b6pgq95nf.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.8veioi0fqa4sg8iacsx8988h4.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.9sx5pblzil93xoy5d97sxzdsf.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.a0rbnexsajt0tkqn96rbownpw.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.a4bfn72ljl404zvmpscy9ws3n.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.a4iy02a2zlqzqb7i81laqabac.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.ayskqwlb4nmazx7uma9fu40en.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.ckuklrcrfprlwatgvyblvmkss.rcgu.o" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.co5q068a5fz1p5yl1jg9c2knm.rcgu.o" "ntoskrnl.lib" "C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\libwinapi-c7d11ea3ccbf4359.rlib" "C:\\Users\\zen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-5a536bba43fbe272.rlib" "C:\\Users\\zen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-45b7a05b67ddb8c6.rlib" "C:\\Users\\zen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-0a4b04fca3ab5f90.rlib" "/defaultlib:msvcrt" "/NXCOMPAT" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.22621.0\\km\\x64" "/OUT:C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.dll" "/OPT:REF,NOICF" "/DLL" "/IMPLIB:C:\\Users\\zen\\Desktop\\drv\\hello_map\\target\\x86_64-pc-windows-msvc\\debug\\deps\\hello_map.dll.lib" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:C:\\Users\\zen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\zen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\zen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\zen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis" "/OPT:REF,ICF" "/ENTRY:driver_entry" "/MERGE:.edata=.rdata" "/MERGE:.rustc=.data" "/INTEGRITYCHECK"
= note: LINK : warning LNK4216: Exported entry point driver_entry␍
Creating library C:\Users\zen\Desktop\drv\hello_map\target\x86_64-pc-windows-msvc\debug\deps\hello_map.dll.lib and object C:\Users\zen\Desktop\drv\hello_map\target\x86_64-pc-windows-msvc\debug\deps\hello_map.dll.exp␍
hello_map.co5q068a5fz1p5yl1jg9c2knm.rcgu.o : error LNK2019: unresolved external symbol NtGdiBitBlt referenced in function _ZN9hello_map4draw19kernel_draw_example17h9370dcbe64bf3303E␍
C:\Users\zen\Desktop\drv\hello_map\target\x86_64-pc-windows-msvc\debug\deps\hello_map.dll : fatal error LNK1120: 1 unresolved externals␍
warning: `hello_map` (lib) generated 15 warnings
error: could not compile `hello_map` (lib) due to 1 previous error; 15 warnings emitted
Я гуглил и там пишут измеить тулчейн но мне нужен конкретно nightly. Visual cpp тоже устанавливал.