Commit e8cafa57 authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

Properly implement DllCanUnloadNow ref counting.

parent 475a81a8
......@@ -41,6 +41,8 @@ ULONG WINAPI IDirectMusicBufferImpl_AddRef (LPDIRECTMUSICBUFFER iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -53,6 +55,9 @@ ULONG WINAPI IDirectMusicBufferImpl_Release (LPDIRECTMUSICBUFFER iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -42,6 +42,8 @@ ULONG WINAPI IReferenceClockImpl_AddRef (IReferenceClock *iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -54,6 +56,9 @@ ULONG WINAPI IReferenceClockImpl_Release (IReferenceClock *iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -58,6 +58,8 @@ ULONG WINAPI IDirectMusicCollectionImpl_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -70,6 +72,9 @@ ULONG WINAPI IDirectMusicCollectionImpl_IUnknown_Release (LPUNKNOWN iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -44,6 +44,8 @@ ULONG WINAPI IDirectMusic8Impl_AddRef (LPDIRECTMUSIC8 iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -56,6 +58,9 @@ ULONG WINAPI IDirectMusic8Impl_Release (LPDIRECTMUSIC8 iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -23,41 +23,48 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
LONG DMUSIC_refCount = 0;
typedef struct {
/* IUnknown fields */
IClassFactoryVtbl *lpVtbl;
DWORD ref;
} IClassFactoryImpl;
/******************************************************************
* DirectMusic ClassFactory
*/
static HRESULT WINAPI DirectMusicCF_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 DirectMusicCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return InterlockedIncrement(&This->ref);
DMUSIC_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI DirectMusicCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return InterlockedDecrement(&This->ref);
DMUSIC_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI DirectMusicCF_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_CreateDirectMusicImpl (riid, (LPVOID*) ppobj, pOuter);
}
static HRESULT WINAPI DirectMusicCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMUSIC_LockModule();
else
DMUSIC_UnlockModule();
return S_OK;
}
......@@ -69,37 +76,44 @@ static IClassFactoryVtbl DirectMusicCF_Vtbl = {
DirectMusicCF_LockServer
};
static IClassFactoryImpl DirectMusic_CF = {&DirectMusicCF_Vtbl, 1 };
static IClassFactoryImpl DirectMusic_CF = {&DirectMusicCF_Vtbl};
/******************************************************************
* DirectMusicCollection ClassFactory
*/
static HRESULT WINAPI CollectionCF_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 CollectionCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return InterlockedIncrement(&This->ref);
DMUSIC_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI CollectionCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return InterlockedDecrement(&This->ref);
DMUSIC_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI CollectionCF_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_CreateDirectMusicCollectionImpl (riid, ppobj, pOuter);
}
static HRESULT WINAPI CollectionCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMUSIC_LockModule();
else
DMUSIC_UnlockModule();
return S_OK;
}
......@@ -111,7 +125,7 @@ static IClassFactoryVtbl CollectionCF_Vtbl = {
CollectionCF_LockServer
};
static IClassFactoryImpl Collection_CF = {&CollectionCF_Vtbl, 1 };
static IClassFactoryImpl Collection_CF = {&CollectionCF_Vtbl};
/******************************************************************
* DllMain
......@@ -136,8 +150,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
*
*/
HRESULT WINAPI DMUSIC_DllCanUnloadNow(void) {
FIXME("(void): stub\n");
return S_FALSE;
return DMUSIC_refCount != 0 ? S_FALSE : S_OK;
}
......
......@@ -402,6 +402,12 @@ extern HRESULT WINAPI IDirectMusicInstrumentImpl_IDirectMusicInstrument_SetPatch
/* custom :) */
extern HRESULT WINAPI IDirectMusicInstrumentImpl_Custom_Load (LPDIRECTMUSICINSTRUMENT iface, LPSTREAM pStm);
/**********************************************************************
* Dll lifetime tracking declaration for dmusic.dll
*/
extern LONG DMUSIC_refCount;
static inline void DMUSIC_LockModule() { InterlockedIncrement( &DMUSIC_refCount ); }
static inline void DMUSIC_UnlockModule() { InterlockedDecrement( &DMUSIC_refCount ); }
/*****************************************************************************
* Helper Functions
......
......@@ -42,6 +42,8 @@ ULONG WINAPI IDirectMusicDownloadImpl_AddRef (LPDIRECTMUSICDOWNLOAD iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -54,6 +56,9 @@ ULONG WINAPI IDirectMusicDownloadImpl_Release (LPDIRECTMUSICDOWNLOAD iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -42,6 +42,8 @@ ULONG WINAPI IDirectMusicDownloadedInstrumentImpl_AddRef (LPDIRECTMUSICDOWNLOADE
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -54,6 +56,9 @@ ULONG WINAPI IDirectMusicDownloadedInstrumentImpl_Release (LPDIRECTMUSICDOWNLOAD
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -58,6 +58,8 @@ ULONG WINAPI IDirectMusicInstrumentImpl_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -70,6 +72,9 @@ ULONG WINAPI IDirectMusicInstrumentImpl_IUnknown_Release (LPUNKNOWN iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -41,6 +41,8 @@ ULONG WINAPI IDirectMusicPortImpl_AddRef (LPDIRECTMUSICPORT iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -53,6 +55,9 @@ ULONG WINAPI IDirectMusicPortImpl_Release (LPDIRECTMUSICPORT iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -41,6 +41,8 @@ ULONG WINAPI IDirectMusicPortDownloadImpl_AddRef (LPDIRECTMUSICPORTDOWNLOAD ifac
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -53,6 +55,9 @@ ULONG WINAPI IDirectMusicPortDownloadImpl_Release (LPDIRECTMUSICPORTDOWNLOAD ifa
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
......@@ -42,6 +42,8 @@ ULONG WINAPI IDirectMusicThruImpl_AddRef (LPDIRECTMUSICTHRU iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMUSIC_LockModule();
return refCount;
}
......@@ -54,6 +56,9 @@ ULONG WINAPI IDirectMusicThruImpl_Release (LPDIRECTMUSICTHRU iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMUSIC_UnlockModule();
return refCount;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment