[Spice-devel] [vdagent-win PATCH v4 16/19] Avoids to call supported_system_version()

Jonathon Jongsma jjongsma at redhat.com
Thu Jul 5 16:38:09 UTC 2018


Seems reasonable

Acked-by: Jonathon Jongsma <jjongsma at redhat.com>



On Mon, 2018-07-02 at 08:43 +0100, Frediano Ziglio wrote:
> The only reason we call this function is to check if the
> system should support some APIs.
> Instead just check directly if these APIs are supported
> calling GetProcAddress directly.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  vdagent/vdagent.cpp | 29 +++++++++++++++--------------
>  1 file changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
> index 631f27c..9a40388 100644
> --- a/vdagent/vdagent.cpp
> +++ b/vdagent/vdagent.cpp
> @@ -269,21 +269,22 @@ bool VDAgent::run()
>      if (!SetProcessShutdownParameters(0x100, 0)) {
>          vd_printf("SetProcessShutdownParameters failed %lu",
> GetLastError());
>      }
> -    if (supported_system_version() == SYS_VER_WIN_7_CLASS) {
> -        HMODULE _user_lib = GetModuleHandle(L"User32");
> -        if (!_user_lib) {
> -            vd_printf("GetModuleHandle failed %lu", GetLastError());
> -            return false;
> -        }
> -        _add_clipboard_listener =
> -            (PCLIPBOARD_OP)GetProcAddress(_user_lib,
> "AddClipboardFormatListener");
> -        _remove_clipboard_listener =
> -            (PCLIPBOARD_OP)GetProcAddress(_user_lib,
> "RemoveClipboardFormatListener");
> -        if (!_add_clipboard_listener || !_remove_clipboard_listener)
> {
> -            vd_printf("GetProcAddress failed %lu", GetLastError());
> -            return false;
> -        }
> +
> +    HMODULE _user_lib = GetModuleHandle(L"User32");
> +    if (!_user_lib) {
> +        vd_printf("GetModuleHandle failed %lu", GetLastError());
> +        return false;
>      }
> +    _add_clipboard_listener =
> +        (PCLIPBOARD_OP)GetProcAddress(_user_lib,
> "AddClipboardFormatListener");
> +    _remove_clipboard_listener =
> +        (PCLIPBOARD_OP)GetProcAddress(_user_lib,
> "RemoveClipboardFormatListener");
> +    // do not use FormatListener APIs if not available
> +    if (!_add_clipboard_listener || !_remove_clipboard_listener) {
> +        _add_clipboard_listener = nullptr;
> +        _remove_clipboard_listener = nullptr;
> +    }
> +
>      if (!_control_event)
>          _control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
>      if (!_control_event) {


More information about the Spice-devel mailing list