Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Last active October 13, 2021 23:54
Show Gist options
  • Save kennykerr/ab14d4034f3a82a60aad65389c41315e to your computer and use it in GitHub Desktop.
Save kennykerr/ab14d4034f3a82a60aad65389c41315e to your computer and use it in GitHub Desktop.
#include <Unknwn.h>
#include <winrt/Windows.Foundation.h>
using namespace winrt;
using namespace Windows::Foundation;
struct Stringable : implements<Stringable, IStringable>
{
hstring ToString()
{
return L"Hello from server";
}
};
struct Factory : implements<Factory, IClassFactory>
{
HRESULT __stdcall CreateInstance(
IUnknown* outer,
GUID const& iid,
void** result) noexcept final
{
*result = nullptr;
if (outer)
{
return CLASS_E_NOAGGREGATION;
}
return make<Stringable>().as(iid, result);
}
HRESULT __stdcall LockServer(BOOL) noexcept final
{
return S_OK;
}
};
static constexpr GUID server_clsid // DAA16D7F-EF66-4FC9-B6F2-3E5B6D924576
{
0xdaa16d7f, 0xef66, 0x4fc9, { 0xb6, 0xf2, 0x3e, 0x5b, 0x6d, 0x92, 0x45, 0x76 }
};
int main()
{
init_apartment();
DWORD registration{};
check_hresult(CoRegisterClassObject(
server_clsid,
make<Factory>().get(),
CLSCTX_LOCAL_SERVER,
REGCLS_SINGLEUSE,
&registration));
puts("Press Enter me when you're done serving.");
getchar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment