Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Last active March 6, 2025 22:13
Show Gist options
  • Save kennykerr/d2396bc6e06809bec64e4ff5ac71ccd8 to your computer and use it in GitHub Desktop.
Save kennykerr/d2396bc6e06809bec64e4ff5ac71ccd8 to your computer and use it in GitHub Desktop.
#include <Unknwn.h>
#include "winrt/Windows.Foundation.h"
namespace winrt {
using namespace Windows::Foundation;
}
class __declspec(uuid("58d39529-4975-4440-b7a6-6d71bfb59559")) CLSID_SAMPLE;
int main() {
CO_MTA_USAGE_COOKIE cookie{};
CoIncrementMTAUsage(&cookie);
while (true) {
printf(".");
auto stringable =
winrt::create_instance<winrt::IStringable>(__uuidof(CLSID_SAMPLE), CLSCTX_LOCAL_SERVER);
assert(stringable.ToString() == L"Stringable");
winrt::com_ptr<IStream> stream;
winrt::check_hresult(CoMarshalInterThreadInterfaceInStream(
winrt::guid_of<winrt::IStringable>(),
winrt::get_unknown(stringable),
stream.put()));
winrt::IStringable copy;
winrt::check_hresult(CoUnmarshalInterface(
stream.get(),
winrt::guid_of<winrt::IStringable>(),
winrt::put_abi(copy)));
}
}
#include <Unknwn.h>
#include "winrt/Windows.Foundation.h"
namespace winrt {
using namespace Windows::Foundation;
}
class __declspec(uuid("58d39529-4975-4440-b7a6-6d71bfb59559")) CLSID_SAMPLE;
struct Stringable : winrt::implements<Stringable, winrt::IStringable> {
winrt::hstring ToString() {
return L"Stringable";
}
};
struct Factory : winrt::implements<Factory, IClassFactory> {
HRESULT __stdcall CreateInstance(IUnknown*, GUID const& iid, void** object) {
auto stringable = winrt::make<Stringable>();
return stringable.as(iid, object);
}
HRESULT __stdcall LockServer(BOOL) {
return S_OK;
}
};
int main() {
CO_MTA_USAGE_COOKIE cookie{};
winrt::check_hresult(CoIncrementMTAUsage(&cookie));
auto factory = winrt::make<Factory>();
DWORD revoke = 0;
winrt::check_hresult(CoRegisterClassObject(
__uuidof(CLSID_SAMPLE),
factory.get(),
CLSCTX_LOCAL_SERVER,
REGCLS_AGILE | REGCLS_MULTIPLEUSE,
&revoke
));
printf("Running!\n");
getchar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment