[Spice-devel] [vdagent-win PATCH v5 1/6] Use GetModuleHandle to get some functions from user32 library
Frediano Ziglio
fziglio at redhat.com
Wed Jul 18 09:46:34 UTC 2018
>
> On Mon, Jul 09, 2018 at 09:51:39AM +0100, Frediano Ziglio wrote:
> > The library is surely already loaded as providing clipboard and
> > other utilities we need.
> > Avoid using LoadLibrary that increment the reference so we don't
> > need to call FreeLibrary to cleanly decrement the reference.
>
> Dunno, feels safer to me to load it explicitly if we need it rather than
> assuming something else will have loaded it.
>
> Christophe
>
For such an application is not far from checking if we are using libc on Unix.
I think for win32 applications (on Windows you can have no-win32 applications)
is the second library (first kernel32).
> >
> > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > ---
> > vdagent/vdagent.cpp | 7 ++-----
> > 1 file changed, 2 insertions(+), 5 deletions(-)
> >
> > diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
> > index 423c3ee..dbf6556 100644
> > --- a/vdagent/vdagent.cpp
> > +++ b/vdagent/vdagent.cpp
> > @@ -125,7 +125,6 @@ private:
> > static VDAgent* _singleton;
> > HWND _hwnd;
> > HWND _hwnd_next_viewer;
> > - HMODULE _user_lib;
> > PCLIPBOARD_OP _add_clipboard_listener;
> > PCLIPBOARD_OP _remove_clipboard_listener;
> > clipboard_owner_t _clipboard_owner;
> > @@ -183,7 +182,6 @@ VDAgent* VDAgent::get()
> > VDAgent::VDAgent()
> > : _hwnd (NULL)
> > , _hwnd_next_viewer (NULL)
> > - , _user_lib (NULL)
> > , _add_clipboard_listener (NULL)
> > , _remove_clipboard_listener (NULL)
> > , _clipboard_owner (owner_none)
> > @@ -269,9 +267,9 @@ bool VDAgent::run()
> > vd_printf("SetProcessShutdownParameters failed %lu",
> > GetLastError());
> > }
> >
> > - _user_lib = LoadLibrary(L"User32.dll");
> > + HMODULE _user_lib = GetModuleHandle(L"User32");
> > if (!_user_lib) {
> > - vd_printf("LoadLibrary failed %lu", GetLastError());
> > + vd_printf("GetModuleHandle failed %lu", GetLastError());
> > return false;
> > }
> > _add_clipboard_listener =
> > @@ -342,7 +340,6 @@ bool VDAgent::run()
> >
> > void VDAgent::cleanup()
> > {
> > - FreeLibrary(_user_lib);
> > CloseHandle(_vio_serial);
> > }
> >
More information about the Spice-devel
mailing list