Last active
October 13, 2021 23:54
-
-
Save kennykerr/ab14d4034f3a82a60aad65389c41315e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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, | |
®istration)); | |
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