From 8159f473ccb69db78c1de1a896fb3eeea0902925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 6 May 2026 15:01:40 +0800 Subject: [PATCH] Common (Windows): allows COM be used in C sources --- CMakeLists.txt | 2 +- src/common/windows/{com.cpp => com.c} | 2 +- src/common/windows/{com.hpp => com.h} | 20 ++++++++++---------- src/detection/camera/camera_windows.cpp | 2 +- src/detection/media/media_windows.cpp | 3 +-- src/detection/sound/sound_windows.cpp | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) rename src/common/windows/{com.cpp => com.c} (98%) rename src/common/windows/{com.hpp => com.h} (52%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f4d3b2f8..5b3ebf061 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1033,7 +1033,7 @@ elseif(WIN32) src/common/impl/debug_windows.c src/common/impl/kmod_windows.c src/common/windows/getline.c - src/common/windows/com.cpp + src/common/windows/com.c src/common/windows/registry.c src/common/windows/unicode.c src/common/windows/variant.cpp diff --git a/src/common/windows/com.cpp b/src/common/windows/com.c similarity index 98% rename from src/common/windows/com.cpp rename to src/common/windows/com.c index 924baf414..0eb566f8b 100644 --- a/src/common/windows/com.cpp +++ b/src/common/windows/com.c @@ -1,4 +1,4 @@ -#include "com.hpp" +#include "com.h" #include diff --git a/src/common/windows/com.hpp b/src/common/windows/com.h similarity index 52% rename from src/common/windows/com.hpp rename to src/common/windows/com.h index eb6b10611..57b8c6d81 100644 --- a/src/common/windows/com.hpp +++ b/src/common/windows/com.h @@ -1,23 +1,23 @@ #pragma once -#ifdef __cplusplus - - #include "common/attributes.h" - #include +#include "common/attributes.h" +#include +#include // Initialize COM & WinRT const char* ffInitCom(void); static inline void ffReleaseComObject(void* ppUnknown) { + assert(ppUnknown); IUnknown* pUnknown = *(IUnknown**) ppUnknown; if (pUnknown) { +#ifdef __cplusplus pUnknown->Release(); +#else + pUnknown->lpVtbl->Release(pUnknown); +#endif + *(IUnknown**) ppUnknown = NULL; } } - #define FF_AUTO_RELEASE_COM_OBJECT FF_A_CLEANUP(ffReleaseComObject) - -#else - // Win32 COM headers requires C++ compiler - #error Must be included in C++ source file -#endif +#define FF_AUTO_RELEASE_COM_OBJECT FF_A_CLEANUP(ffReleaseComObject) diff --git a/src/detection/camera/camera_windows.cpp b/src/detection/camera/camera_windows.cpp index 48ee9dc45..087cc6d5f 100644 --- a/src/detection/camera/camera_windows.cpp +++ b/src/detection/camera/camera_windows.cpp @@ -1,8 +1,8 @@ extern "C" { #include "camera.h" #include "common/library.h" +#include "common/windows/com.h" } -#include "common/windows/com.hpp" #include "common/windows/unicode.hpp" #include "common/windows/util.hpp" diff --git a/src/detection/media/media_windows.cpp b/src/detection/media/media_windows.cpp index 9a92440e3..10d9ee5d3 100644 --- a/src/detection/media/media_windows.cpp +++ b/src/detection/media/media_windows.cpp @@ -2,6 +2,7 @@ extern "C" { #include "media.h" #include "common/time.h" #include "common/windows/unicode.h" +#include "common/windows/com.h" } #if FF_HAVE_WINRT @@ -15,8 +16,6 @@ extern "C" { #include #include - #include "common/windows/com.hpp" - #define FF_BIND_FRONT(method, pobject) std::bind_front(&std::remove_cvref_t::method, (pobject)) using winrt::impl::abi_t; diff --git a/src/detection/sound/sound_windows.cpp b/src/detection/sound/sound_windows.cpp index 835eb63a2..6d6307a5d 100644 --- a/src/detection/sound/sound_windows.cpp +++ b/src/detection/sound/sound_windows.cpp @@ -1,8 +1,8 @@ extern "C" { #include "sound.h" +#include "common/windows/com.h" } #include "common/windows/unicode.hpp" -#include "common/windows/com.hpp" #include "common/windows/variant.hpp" #include