mirror of
https://github.com/solemnwarning/directplay-lite
synced 2024-12-30 16:45:37 +01:00
The threading model used for processing messages here will need redesigning; we can't allow the application to block the event loop when processing a message in case it calls something which won't return until a message is processed. Final model will probably use a pool of workers which will handle I/O one-at-a-time, blocking and allowing other threads to deal with the I/O when in the application message callback.
50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
#include <winsock2.h>
|
|
#include <atomic>
|
|
#include <dplay8.h>
|
|
#include <objbase.h>
|
|
#include <windows.h>
|
|
|
|
#include "DirectPlay8Address.hpp"
|
|
#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_DirectPlay8Address)
|
|
{
|
|
*((IUnknown**)(ppv)) = new Factory<DirectPlay8Address, IID_IDirectPlay8Address>(&global_refcount);
|
|
return S_OK;
|
|
}
|
|
else if(rclsid == CLSID_DirectPlay8Peer)
|
|
{
|
|
*((IUnknown**)(ppv)) = new Factory<DirectPlay8Peer, IID_IDirectPlay8Peer>(&global_refcount);
|
|
return S_OK;
|
|
}
|
|
else{
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
}
|
|
}
|