From 3c57260ddb82873c02ed90856c4b66c5a3cfd92e Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Sat, 11 Jul 2026 02:11:22 +0300 Subject: [PATCH] fix(thumbnailer-win): make the COM DLL compile on the MSVC target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First real Windows build surfaced errors that a Linux host couldn't catch: * Enable the missing `windows` feature gates (Win32_System_LibraryLoader, Win32_System_SystemServices, Win32_Security — the last brings in the `Ex` registry APIs) so the imports resolve. * Depend on `windows-core`: the `#[implement]` macro expands to `windows_core::` paths, which need the crate nameable in the root. * `IClassFactory::LockServer` takes `Win32::Foundation::BOOL`, not a `core` BOOL. * Name the returned image type via a new `dwg_thumbnailer::RgbaImage` re-export instead of a direct `image` dependency. Verified with `cargo check --target x86_64-pc-windows-gnu -p dwg-thumbnailer-win` (and the native check still passes). Co-Authored-By: Claude Opus 4.8 --- Cargo.lock | 1 + crates/dwg-thumbnailer-win/Cargo.toml | 6 ++++++ crates/dwg-thumbnailer-win/src/lib.rs | 4 ++-- crates/dwg-thumbnailer/src/lib.rs | 5 ++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9fc3736c..c2029d9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1428,6 +1428,7 @@ version = "0.1.0" dependencies = [ "dwg-thumbnailer", "windows 0.58.0", + "windows-core 0.58.0", ] [[package]] diff --git a/crates/dwg-thumbnailer-win/Cargo.toml b/crates/dwg-thumbnailer-win/Cargo.toml index 9750103e..6b94b780 100644 --- a/crates/dwg-thumbnailer-win/Cargo.toml +++ b/crates/dwg-thumbnailer-win/Cargo.toml @@ -14,12 +14,18 @@ crate-type = ["cdylib"] dwg_thumbnailer = { package = "dwg-thumbnailer", path = "../dwg-thumbnailer" } [target.'cfg(windows)'.dependencies] +# `#[implement]` expands to `windows_core::` paths, so the core crate must be +# nameable in the crate root (kept in lockstep with the `windows` version). +windows-core = "0.58" windows = { version = "0.58", features = [ "implement", "Win32_Foundation", + "Win32_Security", "Win32_System_Com", "Win32_System_Com_StructuredStorage", + "Win32_System_LibraryLoader", "Win32_System_Registry", + "Win32_System_SystemServices", "Win32_UI_Shell", "Win32_UI_Shell_PropertiesSystem", "Win32_Graphics_Gdi", diff --git a/crates/dwg-thumbnailer-win/src/lib.rs b/crates/dwg-thumbnailer-win/src/lib.rs index 07f8310d..3d294726 100644 --- a/crates/dwg-thumbnailer-win/src/lib.rs +++ b/crates/dwg-thumbnailer-win/src/lib.rs @@ -99,7 +99,7 @@ impl IThumbnailProvider_Impl for DwgThumbProvider_Impl { } /// Build a 32-bit top-down BGRA `HBITMAP` from an RGBA image. -unsafe fn rgba_to_hbitmap(img: &image::RgbaImage) -> windows::core::Result { +unsafe fn rgba_to_hbitmap(img: &dwg_thumbnailer::RgbaImage) -> windows::core::Result { let (w, h) = (img.width() as i32, img.height() as i32); let bi = BITMAPINFO { bmiHeader: BITMAPINFOHEADER { @@ -148,7 +148,7 @@ impl IClassFactory_Impl for Factory_Impl { unsafe { provider.query(&*riid, ppvobject).ok() } } - fn LockServer(&self, _flock: windows::core::BOOL) -> windows::core::Result<()> { + fn LockServer(&self, _flock: windows::Win32::Foundation::BOOL) -> windows::core::Result<()> { Ok(()) } } diff --git a/crates/dwg-thumbnailer/src/lib.rs b/crates/dwg-thumbnailer/src/lib.rs index 3d8f27fb..4f62bf62 100644 --- a/crates/dwg-thumbnailer/src/lib.rs +++ b/crates/dwg-thumbnailer/src/lib.rs @@ -11,7 +11,10 @@ use std::path::Path; -use image::{ImageFormat, RgbaImage}; +use image::ImageFormat; +// Re-exported so downstream crates (the Windows/macOS handlers) can name the +// returned image type without taking their own direct `image` dependency. +pub use image::RgbaImage; /// Read the DWG at `path`, extract its embedded preview, and scale it so the /// longest edge is at most `max_dim` pixels (aspect preserved). Returns `None`