Properly implement DllCanUnloadNow ref counting.

This commit is contained in:
James Hawkins 2004-12-09 13:46:47 +00:00 committed by Alexandre Julliard
parent 7a03fd6763
commit f238cd88e8
6 changed files with 138 additions and 65 deletions

View file

@ -55,6 +55,9 @@ HRESULT WINAPI IDirectMusicChordMapImpl_IUnknown_QueryInterface (LPUNKNOWN iface
ULONG WINAPI IDirectMusicChordMapImpl_IUnknown_AddRef (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicChordMapImpl, UnknownVtbl, iface);
TRACE("(%p): AddRef from %ld\n", This, This->ref);
DMCOMPOS_LockModule();
return ++(This->ref);
}
@ -62,9 +65,13 @@ ULONG WINAPI IDirectMusicChordMapImpl_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicChordMapImpl, UnknownVtbl, iface);
ULONG ref = --This->ref;
TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMCOMPOS_UnlockModule();
return ref;
}

View file

@ -52,6 +52,9 @@ HRESULT WINAPI IDirectMusicChordMapTrack_IUnknown_QueryInterface (LPUNKNOWN ifac
ULONG WINAPI IDirectMusicChordMapTrack_IUnknown_AddRef (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicChordMapTrack, UnknownVtbl, iface);
TRACE("(%p): AddRef from %ld\n", This, This->ref);
DMCOMPOS_LockModule();
return ++(This->ref);
}
@ -59,9 +62,13 @@ ULONG WINAPI IDirectMusicChordMapTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicChordMapTrack, UnknownVtbl, iface);
ULONG ref = --This->ref;
TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMCOMPOS_UnlockModule();
return ref;
}

View file

@ -39,6 +39,9 @@ HRESULT WINAPI IDirectMusicComposerImpl_QueryInterface (LPDIRECTMUSICCOMPOSER if
ULONG WINAPI IDirectMusicComposerImpl_AddRef (LPDIRECTMUSICCOMPOSER iface) {
IDirectMusicComposerImpl *This = (IDirectMusicComposerImpl *)iface;
TRACE("(%p): AddRef from %ld\n", This, This->ref);
DMCOMPOS_LockModule();
return ++(This->ref);
}
@ -46,9 +49,13 @@ ULONG WINAPI IDirectMusicComposerImpl_Release (LPDIRECTMUSICCOMPOSER iface) {
IDirectMusicComposerImpl *This = (IDirectMusicComposerImpl *)iface;
ULONG ref = --This->ref;
TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMCOMPOS_UnlockModule();
return ref;
}

View file

@ -21,41 +21,49 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmcompos);
LONG DMCOMPOS_refCount = 0;
typedef struct {
/* IUnknown fields */
IClassFactoryVtbl *lpVtbl;
DWORD ref;
} IClassFactoryImpl;
/******************************************************************
* DirectMusicChordMap ClassFactory
*/
static HRESULT WINAPI ChordMapCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n", This, debugstr_dmguid(riid), ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI ChordMapCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
DMCOMPOS_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI ChordMapCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return --(This->ref);
DMCOMPOS_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI ChordMapCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
return DMUSIC_CreateDirectMusicChordMapImpl (riid, ppobj, pOuter);
}
static HRESULT WINAPI ChordMapCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMCOMPOS_LockModule();
else
DMCOMPOS_UnlockModule();
return S_OK;
}
@ -67,37 +75,45 @@ static IClassFactoryVtbl ChordMapCF_Vtbl = {
ChordMapCF_LockServer
};
static IClassFactoryImpl ChordMap_CF = {&ChordMapCF_Vtbl, 1 };
static IClassFactoryImpl ChordMap_CF = {&ChordMapCF_Vtbl};
/******************************************************************
* DirectMusicComposer ClassFactory
*/
static HRESULT WINAPI ComposerCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n",This,debugstr_dmguid(riid),ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI ComposerCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
DMCOMPOS_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI ComposerCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return --(This->ref);
DMCOMPOS_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI ComposerCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
return DMUSIC_CreateDirectMusicComposerImpl (riid, ppobj, pOuter);
}
static HRESULT WINAPI ComposerCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMCOMPOS_LockModule();
else
DMCOMPOS_UnlockModule();
return S_OK;
}
@ -109,37 +125,45 @@ static IClassFactoryVtbl ComposerCF_Vtbl = {
ComposerCF_LockServer
};
static IClassFactoryImpl Composer_CF = {&ComposerCF_Vtbl, 1 };
static IClassFactoryImpl Composer_CF = {&ComposerCF_Vtbl};
/******************************************************************
* DirectMusicChordMapTrack ClassFactory
*/
static HRESULT WINAPI ChordMapTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n",This,debugstr_dmguid(riid),ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI ChordMapTrackCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
DMCOMPOS_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI ChordMapTrackCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return --(This->ref);
DMCOMPOS_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI ChordMapTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
return DMUSIC_CreateDirectMusicChordMapTrack (riid, ppobj, pOuter);
}
static HRESULT WINAPI ChordMapTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMCOMPOS_LockModule();
else
DMCOMPOS_UnlockModule();
return S_OK;
}
@ -151,39 +175,47 @@ static IClassFactoryVtbl ChordMapTrackCF_Vtbl = {
ChordMapTrackCF_LockServer
};
static IClassFactoryImpl ChordMapTrack_CF = {&ChordMapTrackCF_Vtbl, 1 };
static IClassFactoryImpl ChordMapTrack_CF = {&ChordMapTrackCF_Vtbl};
/******************************************************************
* DirectMusicTemplate ClassFactory
*/
static HRESULT WINAPI TemplateCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n", This, debugstr_dmguid(riid), ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI TemplateCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
DMCOMPOS_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI TemplateCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return --(This->ref);
DMCOMPOS_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI TemplateCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
/* nothing yet */
WARN("(%p, %s,%p): not found\n", This, debugstr_dmguid(riid), ppobj);
WARN("(%s,%p): not found\n", debugstr_dmguid(riid), ppobj);
return E_NOINTERFACE;
}
static HRESULT WINAPI TemplateCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMCOMPOS_LockModule();
else
DMCOMPOS_UnlockModule();
return S_OK;
}
@ -195,37 +227,45 @@ static IClassFactoryVtbl TemplateCF_Vtbl = {
TemplateCF_LockServer
};
static IClassFactoryImpl Template_CF = {&TemplateCF_Vtbl, 1 };
static IClassFactoryImpl Template_CF = {&TemplateCF_Vtbl};
/******************************************************************
* DirectMusicSignPostTrack ClassFactory
*/
static HRESULT WINAPI SignPostTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n",This,debugstr_dmguid(riid),ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI SignPostTrackCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
DMCOMPOS_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI SignPostTrackCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return --(This->ref);
DMCOMPOS_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI SignPostTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
return DMUSIC_CreateDirectMusicSignPostTrack (riid, ppobj, pOuter);
}
static HRESULT WINAPI SignPostTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMCOMPOS_LockModule();
else
DMCOMPOS_UnlockModule();
return S_OK;
}
@ -237,7 +277,7 @@ static IClassFactoryVtbl SignPostTrackCF_Vtbl = {
SignPostTrackCF_LockServer
};
static IClassFactoryImpl SignPostTrack_CF = {&SignPostTrackCF_Vtbl, 1 };
static IClassFactoryImpl SignPostTrack_CF = {&SignPostTrackCF_Vtbl};
/******************************************************************
* DllMain
@ -263,8 +303,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
*
*/
HRESULT WINAPI DMCOMPOS_DllCanUnloadNow(void) {
FIXME("(void): stub\n");
return S_FALSE;
return DMCOMPOS_refCount != 0 ? S_FALSE : S_OK;
}

View file

@ -237,6 +237,12 @@ extern HRESULT WINAPI IDirectMusicSignPostTrack_IPersistStream_Load (LPPERSISTST
extern HRESULT WINAPI IDirectMusicSignPostTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty);
extern HRESULT WINAPI IDirectMusicSignPostTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize);
/**********************************************************************
* Dll lifetime tracking declaration for dmcompos.dll
*/
extern LONG DMCOMPOS_refCount;
static inline void DMCOMPOS_LockModule() { InterlockedIncrement( &DMCOMPOS_refCount ); }
static inline void DMCOMPOS_UnlockModule() { InterlockedDecrement( &DMCOMPOS_refCount ); }
/*****************************************************************************
* Misc.

View file

@ -52,6 +52,9 @@ HRESULT WINAPI IDirectMusicSignPostTrack_IUnknown_QueryInterface (LPUNKNOWN ifac
ULONG WINAPI IDirectMusicSignPostTrack_IUnknown_AddRef (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicSignPostTrack, UnknownVtbl, iface);
TRACE("(%p): AddRef from %ld\n", This, This->ref);
DMCOMPOS_LockModule();
return ++(This->ref);
}
@ -59,9 +62,13 @@ ULONG WINAPI IDirectMusicSignPostTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicSignPostTrack, UnknownVtbl, iface);
ULONG ref = --This->ref;
TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMCOMPOS_UnlockModule();
return ref;
}