mirror of
https://github.com/solemnwarning/directplay-lite
synced 2024-12-30 16:45:37 +01:00
42 lines
851 B
C++
42 lines
851 B
C++
|
#include <atomic>
|
||
|
#include <objbase.h>
|
||
|
#include <windows.h>
|
||
|
|
||
|
#include "DirectPlay8Peer.hpp"
|
||
|
#include "Factory.hpp"
|
||
|
|
||
|
/* Sum of refcounts of all created COM objects. */
|
||
|
static std::atomic<unsigned int> global_refcount;
|
||
|
|
||
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||
|
{
|
||
|
if(fdwReason == DLL_PROCESS_ATTACH)
|
||
|
{
|
||
|
global_refcount = 0;
|
||
|
}
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
HRESULT CALLBACK DllCanUnloadNow()
|
||
|
{
|
||
|
return (global_refcount == 0 ? S_OK : S_FALSE);
|
||
|
}
|
||
|
|
||
|
HRESULT CALLBACK DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
||
|
{
|
||
|
if(riid != IID_IClassFactory && riid != IID_IUnknown)
|
||
|
{
|
||
|
return CLASS_E_CLASSNOTAVAILABLE;
|
||
|
}
|
||
|
|
||
|
if(rclsid == CLSID_DirectPlay8Peer)
|
||
|
{
|
||
|
*((IUnknown**)(ppv)) = new Factory<DirectPlay8Peer, IID_IDirectPlay8Peer>(&global_refcount);
|
||
|
return S_OK;
|
||
|
}
|
||
|
else{
|
||
|
return CLASS_E_CLASSNOTAVAILABLE;
|
||
|
}
|
||
|
}
|