[PATCH v2 2/8] dllhost: Add ISurrogate stub implementation.
Signed-off-by: Dmitry Timoshkov <dmitry(a)baikal.ru> --- programs/dllhost/Makefile.in | 2 +- programs/dllhost/dllhost.c | 82 +++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/programs/dllhost/Makefile.in b/programs/dllhost/Makefile.in index a92add9c2f0..bca6c208cdc 100644 --- a/programs/dllhost/Makefile.in +++ b/programs/dllhost/Makefile.in @@ -1,5 +1,5 @@ MODULE = dllhost.exe -IMPORTS = ole32 +IMPORTS = ole32 uuid EXTRADLLFLAGS = -mwindows -municode diff --git a/programs/dllhost/dllhost.c b/programs/dllhost/dllhost.c index 10bfb084213..ac1cf0e3d33 100644 --- a/programs/dllhost/dllhost.c +++ b/programs/dllhost/dllhost.c @@ -18,6 +18,8 @@ #include <stdarg.h> +#define COBJMACROS + #include <windef.h> #include <winbase.h> #include <objbase.h> @@ -26,6 +28,73 @@ WINE_DEFAULT_DEBUG_CHANNEL(dllhost); +struct surrogate +{ + ISurrogate ISurrogate_iface; + LONG ref; +}; + +static inline struct surrogate *impl_from_ISurrogate(ISurrogate *iface) +{ + return CONTAINING_RECORD(iface, struct surrogate, ISurrogate_iface); +} + +static HRESULT WINAPI surrogate_QueryInterface(ISurrogate *iface, + REFIID iid, void **ppv) +{ + struct surrogate *surrogate = impl_from_ISurrogate(iface); + + TRACE("(%p,%s,%p)\n", iface, wine_dbgstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(iid, &IID_IUnknown) || + IsEqualIID(iid, &IID_ISurrogate)) + { + ISurrogate_AddRef(&surrogate->ISurrogate_iface); + *ppv = &surrogate->ISurrogate_iface; + return S_OK; + } + + *ppv = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI surrogate_AddRef(ISurrogate *iface) +{ + TRACE("(%p)\n", iface); + return 2; +} + +static ULONG WINAPI surrogate_Release(ISurrogate *iface) +{ + TRACE("(%p)\n", iface); + return 1; +} + +static HRESULT WINAPI surrogate_LoadDllServer(ISurrogate *iface, const CLSID *clsid) +{ + FIXME("(%p,%s): stub\n", iface, wine_dbgstr_guid(clsid)); + return E_NOTIMPL; +} + +static HRESULT WINAPI surrogate_FreeSurrogate(ISurrogate *iface) +{ + FIXME("(%p): stub\n", iface); + return E_NOTIMPL; +} + +static const ISurrogateVtbl Surrogate_Vtbl = +{ + surrogate_QueryInterface, + surrogate_AddRef, + surrogate_Release, + surrogate_LoadDllServer, + surrogate_FreeSurrogate +}; + +static struct surrogate surrogate = { { &Surrogate_Vtbl }, 0 }; + int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE previnst, LPWSTR cmdline, int showcmd) { HRESULT hr; @@ -36,9 +105,20 @@ int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE previnst, LPWSTR cmdline, int sho hr = CLSIDFromString(cmdline, &clsid); if (hr == S_OK) { - FIXME("hosting object %s is not implemented\n", wine_dbgstr_guid(&clsid)); + CoRegisterSurrogate(&surrogate.ISurrogate_iface); + + hr = ISurrogate_LoadDllServer(&surrogate.ISurrogate_iface, &clsid); + if (hr != S_OK) + { + ERR("Can't create instance of %s\n", wine_dbgstr_guid(&clsid)); + goto cleanup; + } + + /* FIXME: wait for FreeSurrogate being called */ + Sleep(INFINITE); } +cleanup: CoUninitialize(); return 0; -- 2.35.1
On Tue, Feb 22, 2022 at 05:49:57PM +0300, Dmitry Timoshkov wrote:
Signed-off-by: Dmitry Timoshkov <dmitry(a)baikal.ru> --- programs/dllhost/Makefile.in | 2 +- programs/dllhost/dllhost.c | 82 +++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/programs/dllhost/Makefile.in b/programs/dllhost/Makefile.in index a92add9c2f0..bca6c208cdc 100644 --- a/programs/dllhost/Makefile.in +++ b/programs/dllhost/Makefile.in @@ -1,5 +1,5 @@ MODULE = dllhost.exe -IMPORTS = ole32 +IMPORTS = ole32 uuid
EXTRADLLFLAGS = -mwindows -municode
diff --git a/programs/dllhost/dllhost.c b/programs/dllhost/dllhost.c index 10bfb084213..ac1cf0e3d33 100644 --- a/programs/dllhost/dllhost.c +++ b/programs/dllhost/dllhost.c @@ -18,6 +18,8 @@
#include <stdarg.h>
+#define COBJMACROS + #include <windef.h> #include <winbase.h> #include <objbase.h> @@ -26,6 +28,73 @@
WINE_DEFAULT_DEBUG_CHANNEL(dllhost);
+struct surrogate +{ + ISurrogate ISurrogate_iface; + LONG ref; +}; + +static inline struct surrogate *impl_from_ISurrogate(ISurrogate *iface) +{ + return CONTAINING_RECORD(iface, struct surrogate, ISurrogate_iface); +} + +static HRESULT WINAPI surrogate_QueryInterface(ISurrogate *iface, + REFIID iid, void **ppv) +{ + struct surrogate *surrogate = impl_from_ISurrogate(iface); + + TRACE("(%p,%s,%p)\n", iface, wine_dbgstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(iid, &IID_IUnknown) || + IsEqualIID(iid, &IID_ISurrogate)) + { + ISurrogate_AddRef(&surrogate->ISurrogate_iface); + *ppv = &surrogate->ISurrogate_iface; + return S_OK; + } + + *ppv = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI surrogate_AddRef(ISurrogate *iface) +{ + TRACE("(%p)\n", iface); + return 2; +} + +static ULONG WINAPI surrogate_Release(ISurrogate *iface) +{ + TRACE("(%p)\n", iface); + return 1; +} + +static HRESULT WINAPI surrogate_LoadDllServer(ISurrogate *iface, const CLSID *clsid) +{ + FIXME("(%p,%s): stub\n", iface, wine_dbgstr_guid(clsid)); + return E_NOTIMPL; +} + +static HRESULT WINAPI surrogate_FreeSurrogate(ISurrogate *iface) +{ + FIXME("(%p): stub\n", iface); + return E_NOTIMPL; +} + +static const ISurrogateVtbl Surrogate_Vtbl = +{ + surrogate_QueryInterface, + surrogate_AddRef, + surrogate_Release, + surrogate_LoadDllServer, + surrogate_FreeSurrogate +}; + +static struct surrogate surrogate = { { &Surrogate_Vtbl }, 0 }; +
In the next patch surrogate gets moved to be a local variable of wWinMain, so it might as well start off there.
int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE previnst, LPWSTR cmdline, int showcmd) { HRESULT hr; @@ -36,9 +105,20 @@ int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE previnst, LPWSTR cmdline, int sho hr = CLSIDFromString(cmdline, &clsid); if (hr == S_OK) { - FIXME("hosting object %s is not implemented\n", wine_dbgstr_guid(&clsid)); + CoRegisterSurrogate(&surrogate.ISurrogate_iface);
CoRegisterSurrogate() is currently a stub. Do we know what this is supposed to do? Huw.
Huw Davies <huw(a)codeweavers.com> wrote:
+static struct surrogate surrogate = { { &Surrogate_Vtbl }, 0 }; +
In the next patch surrogate gets moved to be a local variable of wWinMain, so it might as well start off there.
Sure.
int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE previnst, LPWSTR cmdline, int showcmd) { HRESULT hr; @@ -36,9 +105,20 @@ int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE previnst, LPWSTR cmdline, int sho hr = CLSIDFromString(cmdline, &clsid); if (hr == S_OK) { - FIXME("hosting object %s is not implemented\n", wine_dbgstr_guid(&clsid)); + CoRegisterSurrogate(&surrogate.ISurrogate_iface);
CoRegisterSurrogate() is currently a stub. Do we know what this is supposed to do?
I'd guess that the stored ISurrogate pointer is used from inside of CoFreeUnusedLibraries() to call ISurrogate::FreeSurrogate(). This part still needs to be investigated and implemented. -- Dmitry.
Hi Huw, Dmitry Timoshkov <dmitry(a)baikal.ru> wrote:
CoRegisterSurrogate() is currently a stub. Do we know what this is supposed to do?
I'd guess that the stored ISurrogate pointer is used from inside of CoFreeUnusedLibraries() to call ISurrogate::FreeSurrogate(). This part still needs to be investigated and implemented.
Attached patch (on top of the previosuly sent series) follows https://docs.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-isurroga... and relies on DllCanUnloadNow() being properly implemented in the DLL servers. If it looks good I'll send it later for considering once main patch set is accepted. -- Dmitry.
participants (2)
-
Dmitry Timoshkov -
Huw Davies