[PATCH v2 1/2] qga/vss-win32: Fix ConvertStringToBSTR redefinition with newer MinGW

phind.uet@gmail.com posted 2 patches 1 month, 3 weeks ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Stefan Weil <sw@weilnetz.de>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Kostiantyn Kostiuk <kkostiuk@redhat.com>, Michael Roth <michael.roth@amd.com>
[PATCH v2 1/2] qga/vss-win32: Fix ConvertStringToBSTR redefinition with newer MinGW
Posted by phind.uet@gmail.com 1 month, 3 weeks ago
From: Nguyen Dinh Phi <phind.uet@gmail.com>

Newer versions of MinGW-w64 provide ConvertStringToBSTR() in the
_com_util namespace via <comutil.h>. This causes a redefinition
error when building qemu-ga on Windows with these toolchains.

Add a meson check to detect whether ConvertStringToBSTR is already
available, and conditionally compile our fallback implementation
only when the system does not provide one.

Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
Suggested-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 meson.build               | 12 ++++++++++++
 qga/vss-win32/install.cpp |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/meson.build b/meson.build
index c5710a6a47..5a0f407d6f 100644
--- a/meson.build
+++ b/meson.build
@@ -3299,6 +3299,18 @@ endif
 # Detect host pointer size for the target configuration loop.
 host_long_bits = cc.sizeof('void *') * 8
 
+# Detect if ConvertStringToBSTR has been defined in _com_util namespace
+if host_os == 'windows'
+  has_convert_string_to_bstr = cxx.links('''
+    #include <comutil.h>
+    int main() {
+        BSTR b = _com_util::ConvertStringToBSTR("test");
+        return b ? 0 : 1;
+    }
+  ''')
+  config_host_data.set('CONFIG_CONVERT_STRING_TO_BSTR', has_convert_string_to_bstr)
+endif
+
 ########################
 # Target configuration #
 ########################
diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
index 7b25d9098b..5b7a8e9bc5 100644
--- a/qga/vss-win32/install.cpp
+++ b/qga/vss-win32/install.cpp
@@ -549,6 +549,7 @@ STDAPI DllUnregisterServer(void)
 
 
 /* Support function to convert ASCII string into BSTR (used in _bstr_t) */
+#ifndef CONFIG_CONVERT_STRING_TO_BSTR
 namespace _com_util
 {
     BSTR WINAPI ConvertStringToBSTR(const char *ascii) {
@@ -566,6 +567,7 @@ namespace _com_util
         return bstr;
     }
 }
+#endif
 
 /* Stop QGA VSS provider service using Winsvc API  */
 STDAPI StopService(void)
-- 
2.43.0
Re: [PATCH v2 1/2] qga/vss-win32: Fix ConvertStringToBSTR redefinition with newer MinGW
Posted by Pierrick Bouvier 1 month, 3 weeks ago
On 12/18/25 12:54 AM, phind.uet@gmail.com wrote:
> From: Nguyen Dinh Phi <phind.uet@gmail.com>
> 
> Newer versions of MinGW-w64 provide ConvertStringToBSTR() in the
> _com_util namespace via <comutil.h>. This causes a redefinition
> error when building qemu-ga on Windows with these toolchains.
> 
> Add a meson check to detect whether ConvertStringToBSTR is already
> available, and conditionally compile our fallback implementation
> only when the system does not provide one.
> 
> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
> Suggested-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   meson.build               | 12 ++++++++++++
>   qga/vss-win32/install.cpp |  2 ++
>   2 files changed, 14 insertions(+)
Thanks for the update,
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Re: [PATCH v2 1/2] qga/vss-win32: Fix ConvertStringToBSTR redefinition with newer MinGW
Posted by Kostiantyn Kostiuk 1 month, 3 weeks ago
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>

On Thu, Dec 18, 2025 at 10:55 AM <phind.uet@gmail.com> wrote:

> From: Nguyen Dinh Phi <phind.uet@gmail.com>
>
> Newer versions of MinGW-w64 provide ConvertStringToBSTR() in the
> _com_util namespace via <comutil.h>. This causes a redefinition
> error when building qemu-ga on Windows with these toolchains.
>
> Add a meson check to detect whether ConvertStringToBSTR is already
> available, and conditionally compile our fallback implementation
> only when the system does not provide one.
>
> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
> Suggested-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>  meson.build               | 12 ++++++++++++
>  qga/vss-win32/install.cpp |  2 ++
>  2 files changed, 14 insertions(+)
>
> diff --git a/meson.build b/meson.build
> index c5710a6a47..5a0f407d6f 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -3299,6 +3299,18 @@ endif
>  # Detect host pointer size for the target configuration loop.
>  host_long_bits = cc.sizeof('void *') * 8
>
> +# Detect if ConvertStringToBSTR has been defined in _com_util namespace
> +if host_os == 'windows'
> +  has_convert_string_to_bstr = cxx.links('''
> +    #include <comutil.h>
> +    int main() {
> +        BSTR b = _com_util::ConvertStringToBSTR("test");
> +        return b ? 0 : 1;
> +    }
> +  ''')
> +  config_host_data.set('CONFIG_CONVERT_STRING_TO_BSTR',
> has_convert_string_to_bstr)
> +endif
> +
>  ########################
>  # Target configuration #
>  ########################
> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
> index 7b25d9098b..5b7a8e9bc5 100644
> --- a/qga/vss-win32/install.cpp
> +++ b/qga/vss-win32/install.cpp
> @@ -549,6 +549,7 @@ STDAPI DllUnregisterServer(void)
>
>
>  /* Support function to convert ASCII string into BSTR (used in _bstr_t) */
> +#ifndef CONFIG_CONVERT_STRING_TO_BSTR
>  namespace _com_util
>  {
>      BSTR WINAPI ConvertStringToBSTR(const char *ascii) {
> @@ -566,6 +567,7 @@ namespace _com_util
>          return bstr;
>      }
>  }
> +#endif
>
>  /* Stop QGA VSS provider service using Winsvc API  */
>  STDAPI StopService(void)
> --
> 2.43.0
>
>