Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- programs/dllhost/dllhost.c | 217 ++++++++++++++++++++++++++++++++++++- 1 file changed, 213 insertions(+), 4 deletions(-)
diff --git a/programs/dllhost/dllhost.c b/programs/dllhost/dllhost.c index ac1cf0e3d33..55294efc880 100644 --- a/programs/dllhost/dllhost.c +++ b/programs/dllhost/dllhost.c @@ -28,9 +28,193 @@
WINE_DEFAULT_DEBUG_CHANNEL(dllhost);
+struct factory +{ + IClassFactory IClassFactory_iface; + IMarshal IMarshal_iface; + CLSID clsid; + LONG ref; +}; + +static inline struct factory *impl_from_IClassFactory(IClassFactory *iface) +{ + return CONTAINING_RECORD(iface, struct factory, IClassFactory_iface); +} + +static inline struct factory *impl_from_IMarshal(IMarshal *iface) +{ + return CONTAINING_RECORD(iface, struct factory, IMarshal_iface); +} + +static HRESULT WINAPI factory_QueryInterface(IClassFactory *iface, + REFIID iid, void **ppv) +{ + struct factory *factory = impl_from_IClassFactory(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_IClassFactory)) + { + IClassFactory_AddRef(&factory->IClassFactory_iface); + *ppv = &factory->IClassFactory_iface; + return S_OK; + } + else if (IsEqualIID(iid, &IID_IMarshal)) + { + IClassFactory_AddRef(&factory->IClassFactory_iface); + *ppv = &factory->IMarshal_iface; + return S_OK; + } + + *ppv = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI factory_AddRef(IClassFactory *iface) +{ + struct factory *factory = impl_from_IClassFactory(iface); + ULONG ref = InterlockedIncrement(&factory->ref); + + TRACE("(%p)->%u\n", iface, ref); + return ref; +} + +static ULONG WINAPI factory_Release(IClassFactory *iface) +{ + struct factory *factory = impl_from_IClassFactory(iface); + ULONG ref = InterlockedDecrement(&factory->ref); + + TRACE("(%p)->%u\n", iface, ref); + + if (!ref) + HeapFree(GetProcessHeap(), 0, factory); + + return ref; +} + +static HRESULT WINAPI factory_CreateInstance(IClassFactory *iface, + IUnknown *punkouter, REFIID iid, void **ppv) +{ + FIXME("(%p,%p,%s,%p): stub\n", iface, punkouter, wine_dbgstr_guid(iid), ppv); + return E_NOTIMPL; +} + +static HRESULT WINAPI factory_LockServer(IClassFactory *iface, BOOL lock) +{ + TRACE("(%p,%d)\n", iface, lock); + return S_OK; +} + +static const IClassFactoryVtbl ClassFactory_Vtbl = +{ + factory_QueryInterface, + factory_AddRef, + factory_Release, + factory_CreateInstance, + factory_LockServer +}; + +static HRESULT WINAPI marshal_QueryInterface(IMarshal *iface, REFIID iid, LPVOID *ppv) +{ + struct factory *factory = impl_from_IMarshal(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_IMarshal)) + { + IMarshal_AddRef(&factory->IMarshal_iface); + *ppv = &factory->IMarshal_iface; + return S_OK; + } + + *ppv = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI marshal_AddRef(IMarshal *iface) +{ + struct factory *factory = impl_from_IMarshal(iface); + + TRACE("(%p)\n", iface); + + return IClassFactory_AddRef(&factory->IClassFactory_iface); +} + +static ULONG WINAPI marshal_Release(IMarshal *iface) +{ + struct factory *factory = impl_from_IMarshal(iface); + + TRACE("(%p)\n", iface); + + return IClassFactory_Release(&factory->IClassFactory_iface); +} + +static HRESULT WINAPI marshal_GetUnmarshalClass(IMarshal *iface, REFIID iid, void *pv, + DWORD dwDestContext, void *pvDestContext, DWORD mshlflags, CLSID *clsid) +{ + FIXME("(%p,%s,%p,%08lx,%p,%08lx,%p): stub\n", iface, wine_dbgstr_guid(iid), pv, + dwDestContext, pvDestContext, mshlflags, clsid); + return E_NOTIMPL; +} + +static HRESULT WINAPI marshal_GetMarshalSizeMax(IMarshal *iface, REFIID iid, void *pv, + DWORD dwDestContext, void *pvDestContext, DWORD mshlflags, DWORD *size) +{ + FIXME("(%p,%s,%p,%08lx,%p,%08lx,%p): stub\n", iface, wine_dbgstr_guid(iid), pv, + dwDestContext, pvDestContext, mshlflags, size); + return E_NOTIMPL; +} + +static HRESULT WINAPI marshal_MarshalInterface(IMarshal *iface, IStream *stream, REFIID iid, + void *pv, DWORD dwDestContext, void *pvDestContext, DWORD mshlflags) +{ + FIXME("(%p,%s,%p,%08lx,%p,%08lx): stub\n", stream, wine_dbgstr_guid(iid), pv, dwDestContext, pvDestContext, mshlflags); + return E_NOTIMPL; +} + +static HRESULT WINAPI marshal_UnmarshalInterface(IMarshal *iface, IStream *stream, + REFIID iid, void **ppv) +{ + FIXME("(%p,%p,%s,%p): stub\n", iface, stream, wine_dbgstr_guid(iid), ppv); + return E_NOTIMPL; +} + +static HRESULT WINAPI marshal_ReleaseMarshalData(IMarshal *iface, IStream *stream) +{ + TRACE("(%p,%p)\n", iface, stream); + return S_OK; +} + +static HRESULT WINAPI marshal_DisconnectObject(IMarshal *iface, DWORD reserved) +{ + TRACE("(%p, %08lx)\n", iface, reserved); + return S_OK; +} + +static const IMarshalVtbl Marshal_Vtbl = +{ + marshal_QueryInterface, + marshal_AddRef, + marshal_Release, + marshal_GetUnmarshalClass, + marshal_GetMarshalSizeMax, + marshal_MarshalInterface, + marshal_UnmarshalInterface, + marshal_ReleaseMarshalData, + marshal_DisconnectObject +}; + struct surrogate { ISurrogate ISurrogate_iface; + IClassFactory *factory; + DWORD cookie; LONG ref; };
@@ -74,8 +258,29 @@ static ULONG WINAPI surrogate_Release(ISurrogate *iface)
static HRESULT WINAPI surrogate_LoadDllServer(ISurrogate *iface, const CLSID *clsid) { - FIXME("(%p,%s): stub\n", iface, wine_dbgstr_guid(clsid)); - return E_NOTIMPL; + struct surrogate *surrogate = impl_from_ISurrogate(iface); + struct factory *factory; + HRESULT hr; + + TRACE("(%p,%s)\n", iface, wine_dbgstr_guid(clsid)); + + factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory)); + if (!factory) + return E_OUTOFMEMORY; + + factory->IClassFactory_iface.lpVtbl = &ClassFactory_Vtbl; + factory->IMarshal_iface.lpVtbl = &Marshal_Vtbl; + factory->clsid = *clsid; + factory->ref = 1; + + hr = CoRegisterClassObject(clsid, (IUnknown *)&factory->IClassFactory_iface, + CLSCTX_LOCAL_SERVER, REGCLS_SURROGATE, &surrogate->cookie); + if (hr != S_OK) + IClassFactory_Release(&factory->IClassFactory_iface); + else + surrogate->factory = &factory->IClassFactory_iface; + + return hr; }
static HRESULT WINAPI surrogate_FreeSurrogate(ISurrogate *iface) @@ -93,12 +298,16 @@ static const ISurrogateVtbl Surrogate_Vtbl = surrogate_FreeSurrogate };
-static struct surrogate surrogate = { { &Surrogate_Vtbl }, 0 }; - int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE previnst, LPWSTR cmdline, int showcmd) { HRESULT hr; CLSID clsid; + struct surrogate surrogate; + + surrogate.ISurrogate_iface.lpVtbl = &Surrogate_Vtbl; + surrogate.factory = NULL; + surrogate.cookie = 0; + surrogate.ref = 1;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
On Tue, Feb 22, 2022 at 01:02:33PM +0300, Dmitry Timoshkov wrote:
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru
programs/dllhost/dllhost.c | 217 ++++++++++++++++++++++++++++++++++++- 1 file changed, 213 insertions(+), 4 deletions(-)
This is generating a few -Wformat warnings:
In file included from programs/dllhost/dllhost.c:27: programs/dllhost/dllhost.c: In function ‘factory_AddRef’: programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] 81 | TRACE("(%p)->%u\n", iface, ref); | ^~~~~~~~~~~~ ~~~ | | | ULONG {aka long unsigned int}
Apart from that, the series looks good at first glance.
Huw.
Hi Huw,
thanks for the quick review!
Huw Davies huw@codeweavers.com wrote:
On Tue, Feb 22, 2022 at 01:02:33PM +0300, Dmitry Timoshkov wrote:
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru
programs/dllhost/dllhost.c | 217 ++++++++++++++++++++++++++++++++++++- 1 file changed, 213 insertions(+), 4 deletions(-)
This is generating a few -Wformat warnings:
In file included from programs/dllhost/dllhost.c:27: programs/dllhost/dllhost.c: In function ‘factory_AddRef’: programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] 81 | TRACE("(%p)->%u\n", iface, ref); | ^~~~~~~~~~~~ ~~~ | | | ULONG {aka long unsigned int}
Apart from that, the series looks good at first glance.
I don't get the warnings with clang, will check with a gcc build.
Should I resend with the warnings fixed, or should I wait for more comments?
Dmitry Timoshkov dmitry@baikal.ru wrote:
This is generating a few -Wformat warnings:
In file included from programs/dllhost/dllhost.c:27: programs/dllhost/dllhost.c: In function ‘factory_AddRef’: programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] 81 | TRACE("(%p)->%u\n", iface, ref); | ^~~~~~~~~~~~ ~~~ | | | ULONG {aka long unsigned int}
Apart from that, the series looks good at first glance.
I don't get the warnings with clang, will check with a gcc build.
I don't see this warning in an ELF build either. This is a default build, nothing custom or special. Is there a trick to enable the warnings?
On Tue, Feb 22, 2022 at 05:04:15PM +0300, Dmitry Timoshkov wrote:
Dmitry Timoshkov dmitry@baikal.ru wrote:
This is generating a few -Wformat warnings:
In file included from programs/dllhost/dllhost.c:27: programs/dllhost/dllhost.c: In function ‘factory_AddRef’: programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] 81 | TRACE("(%p)->%u\n", iface, ref); | ^~~~~~~~~~~~ ~~~ | | | ULONG {aka long unsigned int}
Apart from that, the series looks good at first glance.
I don't get the warnings with clang, will check with a gcc build.
I don't see this warning in an ELF build either. This is a default build, nothing custom or special. Is there a trick to enable the warnings?
I'd have thought you'd have seen them in a PE build or in a 32-bit ELF build - ie. whenever ULONG is unsigned long.
Once you have them fixed, send in the series again. I didn't spot anything else that'll need more work.
Huw.
Huw Davies huw@codeweavers.com wrote:
On Tue, Feb 22, 2022 at 05:04:15PM +0300, Dmitry Timoshkov wrote:
Dmitry Timoshkov dmitry@baikal.ru wrote:
This is generating a few -Wformat warnings:
In file included from programs/dllhost/dllhost.c:27: programs/dllhost/dllhost.c: In function ‘factory_AddRef’: programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] 81 | TRACE("(%p)->%u\n", iface, ref); | ^~~~~~~~~~~~ ~~~ | | | ULONG {aka long unsigned int}
Apart from that, the series looks good at first glance.
I don't get the warnings with clang, will check with a gcc build.
I don't see this warning in an ELF build either. This is a default build, nothing custom or special. Is there a trick to enable the warnings?
I'd have thought you'd have seen them in a PE build or in a 32-bit ELF build - ie. whenever ULONG is unsigned long.
No, I don't see these warnings. Moreover, root Makefile contains explicit -Wno-format in CFLAGS. Replacing -Wno-format by -Wformat changes nothing. Again, this is default build, with clang or gcc. So, if I missed some of the warnings at least you know why :)
On Tue, Feb 22, 2022 at 05:57:01PM +0300, Dmitry Timoshkov wrote:
Huw Davies huw@codeweavers.com wrote:
On Tue, Feb 22, 2022 at 05:04:15PM +0300, Dmitry Timoshkov wrote:
Dmitry Timoshkov dmitry@baikal.ru wrote:
This is generating a few -Wformat warnings:
In file included from programs/dllhost/dllhost.c:27: programs/dllhost/dllhost.c: In function ‘factory_AddRef’: programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] 81 | TRACE("(%p)->%u\n", iface, ref); | ^~~~~~~~~~~~ ~~~ | | | ULONG {aka long unsigned int}
Apart from that, the series looks good at first glance.
I don't get the warnings with clang, will check with a gcc build.
I don't see this warning in an ELF build either. This is a default build, nothing custom or special. Is there a trick to enable the warnings?
I'd have thought you'd have seen them in a PE build or in a 32-bit ELF build - ie. whenever ULONG is unsigned long.
No, I don't see these warnings. Moreover, root Makefile contains explicit -Wno-format in CFLAGS. Replacing -Wno-format by -Wformat changes nothing. Again, this is default build, with clang or gcc. So, if I missed some of the warnings at least you know why :)
Right, but makedep.c adds -Wformat in the cross case (yes, I was wrong about the 32-bit ELF build).
Huw.
Huw Davies huw@codeweavers.com wrote:
On Tue, Feb 22, 2022 at 05:57:01PM +0300, Dmitry Timoshkov wrote:
Huw Davies huw@codeweavers.com wrote:
On Tue, Feb 22, 2022 at 05:04:15PM +0300, Dmitry Timoshkov wrote:
Dmitry Timoshkov dmitry@baikal.ru wrote:
This is generating a few -Wformat warnings:
In file included from programs/dllhost/dllhost.c:27: programs/dllhost/dllhost.c: In function ‘factory_AddRef’: programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] 81 | TRACE("(%p)->%u\n", iface, ref); | ^~~~~~~~~~~~ ~~~ | | | ULONG {aka long unsigned int}
Apart from that, the series looks good at first glance.
I don't get the warnings with clang, will check with a gcc build.
I don't see this warning in an ELF build either. This is a default build, nothing custom or special. Is there a trick to enable the warnings?
I'd have thought you'd have seen them in a PE build or in a 32-bit ELF build - ie. whenever ULONG is unsigned long.
No, I don't see these warnings. Moreover, root Makefile contains explicit -Wno-format in CFLAGS. Replacing -Wno-format by -Wformat changes nothing. Again, this is default build, with clang or gcc. So, if I missed some of the warnings at least you know why :)
Right, but makedep.c adds -Wformat in the cross case (yes, I was wrong about the 32-bit ELF build).
As I already mentioned, I don't see the warnings in a clang (PE) build, in both 32 and 64-bit build trees. Probably something is misdetected here?
On 22/02/2022 17:07, Dmitry Timoshkov wrote:
Huw Davies huw@codeweavers.com wrote:
On Tue, Feb 22, 2022 at 05:57:01PM +0300, Dmitry Timoshkov wrote:
Huw Davies huw@codeweavers.com wrote:
On Tue, Feb 22, 2022 at 05:04:15PM +0300, Dmitry Timoshkov wrote:
Dmitry Timoshkov dmitry@baikal.ru wrote:
> This is generating a few -Wformat warnings: > > In file included from programs/dllhost/dllhost.c:27: > programs/dllhost/dllhost.c: In function ‘factory_AddRef’: > programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] > 81 | TRACE("(%p)->%u\n", iface, ref); > | ^~~~~~~~~~~~ ~~~ > | | > | ULONG {aka long unsigned int} > > Apart from that, the series looks good at first glance.
I don't get the warnings with clang, will check with a gcc build.
I don't see this warning in an ELF build either. This is a default build, nothing custom or special. Is there a trick to enable the warnings?
I'd have thought you'd have seen them in a PE build or in a 32-bit ELF build - ie. whenever ULONG is unsigned long.
No, I don't see these warnings. Moreover, root Makefile contains explicit -Wno-format in CFLAGS. Replacing -Wno-format by -Wformat changes nothing. Again, this is default build, with clang or gcc. So, if I missed some of the warnings at least you know why :)
Right, but makedep.c adds -Wformat in the cross case (yes, I was wrong about the 32-bit ELF build).
As I already mentioned, I don't see the warnings in a clang (PE) build, in both 32 and 64-bit build trees. Probably something is misdetected here?
I think this happens on MinGW with GCC 11. It's technically correct, but harmless, so I can see why Clang does not complain. That's because long == int on Windows model, even on 64-bit (i.e. it's still 32 bits), so %u doesn't give a wrong result.
I think this happens on MinGW with GCC 11. It's technically correct, but harmless, so I can see why Clang does not complain. That's because long == int on Windows model, even on 64-bit (i.e. it's still 32 bits), so %u doesn't give a wrong result.
no that's because we need to tell the compiler which routines behave like printf and which of their parameters should be checked as such
here (for TRACE), we have include/wine/debug.h
#if !defined(__WINE_USE_MSVCRT) || defined(__MINGW32__) #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args))) #else #define __WINE_PRINTF_ATTR(fmt,args) #endif
and later
static const char * __wine_dbg_cdecl wine_dbg_sprintf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
hence, we currently assume that __MINGW32__ is defined for enabling this feature
this is fine for gcc/mingw, and also for the clang mingw port, but doesn't work with stock clang
I'll see to improve it
A+
Le 22/02/2022 à 15:04, Dmitry Timoshkov a écrit :
Dmitry Timoshkovdmitry@baikal.ru wrote:
This is generating a few -Wformat warnings:
In file included from programs/dllhost/dllhost.c:27: programs/dllhost/dllhost.c: In function ‘factory_AddRef’: programs/dllhost/dllhost.c:81:11: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ULONG’ {aka ‘long unsigned int’} [-Wformat=] 81 | TRACE("(%p)->%u\n", iface, ref); | ^~~~~~~~~~~~ ~~~ | | | ULONG {aka long unsigned int}
Apart from that, the series looks good at first glance.
I don't get the warnings with clang, will check with a gcc build.
I don't see this warning in an ELF build either. This is a default build, nothing custom or special. Is there a trick to enable the warnings?
Hi Dmitry
they should appear when cross compiling
A+