58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
#include "ScriptHookPlugin.h"
|
|
|
|
#include <windows.h>
|
|
#include <cchannel.h>
|
|
#include <tsvirtualchannels.h>
|
|
#include <new>
|
|
|
|
BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved)
|
|
{
|
|
UNREFERENCED_PARAMETER(reserved);
|
|
if (reason == DLL_PROCESS_ATTACH)
|
|
{
|
|
DisableThreadLibraryCalls(module);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
// Der Prototyp ist laut Microsoft nicht in einem öffentlichen Header enthalten
|
|
// und muss exakt in dieser Form exportiert werden.
|
|
extern "C" __declspec(dllexport) HRESULT VCAPITYPE VirtualChannelGetInstance(
|
|
_In_ REFIID refiid,
|
|
_Inout_ ULONG* pNumObjs,
|
|
_Out_opt_ VOID** ppObjArray)
|
|
{
|
|
if (pNumObjs == nullptr)
|
|
{
|
|
return E_POINTER;
|
|
}
|
|
|
|
if (refiid != __uuidof(IWTSPlugin))
|
|
{
|
|
return E_NOINTERFACE;
|
|
}
|
|
|
|
constexpr ULONG requiredObjects = 1;
|
|
if (ppObjArray == nullptr)
|
|
{
|
|
*pNumObjs = requiredObjects;
|
|
return S_OK;
|
|
}
|
|
|
|
if (*pNumObjs < requiredObjects)
|
|
{
|
|
*pNumObjs = requiredObjects;
|
|
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
|
|
}
|
|
|
|
auto* plugin = new (std::nothrow) ScriptHookPlugin();
|
|
if (plugin == nullptr)
|
|
{
|
|
return E_OUTOFMEMORY;
|
|
}
|
|
|
|
ppObjArray[0] = static_cast<IWTSPlugin*>(plugin);
|
|
*pNumObjs = requiredObjects;
|
|
return S_OK;
|
|
}
|