{"id":886,"date":"2016-05-22T04:11:10","date_gmt":"2016-05-21T19:11:10","guid":{"rendered":"http:\/\/dev.activebasic.com\/egtra\/?p=886"},"modified":"2016-05-22T04:11:10","modified_gmt":"2016-05-21T19:11:10","slug":"registeractiveobject%e3%81%a8rot","status":"publish","type":"post","link":"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/","title":{"rendered":"RegisterActiveObject\u3068ROT"},"content":{"rendered":"<p><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms221551(v=vs.85).aspx\">RegisterActiveObject<\/a>\u95a2\u6570\u306f\u5185\u90e8\u3067Running Object Table (ROT)\u3092\u4f7f\u3063\u3066\u3044\u308b\u3068\u3001MSDN\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3082\u66f8\u304b\u308c\u3066\u3042\u308a\u307e\u3059: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms221675(v=vs.85).aspx\">Registration Functions (Automation)<\/a>\u3002<\/p>\n<p>ROT\u306f\u3001\u30e2\u30cb\u30ab\u30fc\u3092\u30ad\u30fc\u3068\u3057\u3066\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u767b\u9332\u3059\u308b\u3001\u3064\u307e\u308a\u9023\u60f3\u914d\u5217\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002\u306a\u3089\u3070\u3001\u30af\u30e9\u30b9ID\u3092\u30ad\u30fc\u306b\u767b\u9332\u3059\u308bRegisterActiveObject\u306f\u3069\u3046\u3044\u3046\u30e2\u30cb\u30ab\u30fc\u3067ROT\u306b\u767b\u9332\u3059\u308b\u306e\u304b\u3001\u3068\u3044\u3046\u3053\u3068\u3092\u77e5\u308a\u305f\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u8abf\u3079\u305f\u7d50\u679c\u3001\u30af\u30e9\u30b9ID\u306e\u6587\u5b57\u5217\u306e\u30a2\u30a4\u30c6\u30e0\u30e2\u30cb\u30ab\u30fc\u3067\u3042\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3057\u305f\u3002\u3059\u306a\u308f\u3061\u3001\u30e2\u30cb\u30ab\u30fc\u306e\u6587\u5b57\u5217\u8868\u73fe\u306f<code>\"!{XXXXXXXX-\u2026\u2026}\"<\/code>\u3068\u3044\u3046\u5f62\u5f0f\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001RegisterActiveObject\u3067\u767b\u9332\u3057\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092IRunningObjectTable::GetObject\u3067\u53d6\u308a\u51fa\u3057\u305f\u308a\u3001IRunningObjectTable::Register\u3067\u767b\u9332\u3057\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092GetActiveObject\u3067\u53d6\u308a\u51fa\u3057\u305f\u308a\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<pre lang=\"cpp\">\r\n#define UNICODE\r\n#define _UNICODE\r\n#define WIN32_LEAN_AND_MEAN\r\n#define _ATL_NO_AUTOMATIC_NAMESPACE\r\n\r\n#include <iostream>\r\n#include <cstdlib>\r\n#include <windows.h>\r\n#include <atlbase.h>\r\n#include <atlcom.h>\r\n#include <atlutil.h>\r\n\r\n\/\/ {EECAE0DA-5F2B-48E2-9F22-09A788DA83FE}\r\nstatic const GUID CLSID_Hoge =\r\n{\r\n  0xeecae0da, 0x5f2b, 0x48e2,\r\n  { 0x9f, 0x22, 0x9, 0xa7, 0x88, 0xda, 0x83, 0xfe }\r\n};\r\n\r\nstruct Hoge : IUnknown\r\n{\r\n  IFACEMETHOD(QueryInterface)(REFIID riid, void** ppv) override\r\n  {\r\n    if (riid == IID_IUnknown)\r\n    {\r\n      *ppv = (IUnknown*)this;\r\n      return S_OK;\r\n    }\r\n    return E_NOINTERFACE;\r\n  }\r\n  IFACEMETHOD_(DWORD, AddRef)() override { return 1; }\r\n  IFACEMETHOD_(DWORD, Release)() override { return 1; }\r\n};\r\n\r\nvoid ExitIfFailed(_In_ PCWSTR functionName, HRESULT hr)\r\n{\r\n  if (SUCCEEDED(hr))\r\n  {\r\n    return;\r\n  }\r\n  std::wclog << functionName << '\\n';\r\n  std::wclog << std::showbase << std::hex << hr << '\\n';\r\n  std::wclog << ATL::AtlGetErrorDescription(hr).GetString() << std::endl;\r\n  std::quick_exit(static_cast<int>(hr));\r\n}\r\n\r\nint main()\r\n{\r\n  std::wclog.imbue(std::locale(\"\"));\r\n  auto hrInit = CoInitializeEx(\r\n    nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);\r\n  ExitIfFailed(L\"CoInitializeEx\", hrInit);\r\n\r\n  ATL::CComPtr<IRunningObjectTable> rot;\r\n  auto hrRot = GetRunningObjectTable(0, &rot);\r\n  ExitIfFailed(L\"GetRunningObjectTable\", hrRot);\r\n\r\n  ATL::CComPtr<IMoniker> mk;\r\n  auto hrMk = CreateItemMoniker(\r\n    L\"!\", L\"{EECAE0DA-5F2B-48E2-9F22-09A788DA83FE}\", &mk);\r\n  ExitIfFailed(L\"CreateItemMoniker\", hrMk);\r\n\r\n  std::cout << std::boolalpha;\r\n  {\r\n    Hoge obj;\r\n    DWORD reg;\r\n    auto hrReg = RegisterActiveObject(\r\n      &#038;obj, CLSID_Hoge, ACTIVEOBJECT_STRONG, &#038;reg);\r\n    ExitIfFailed(L\"RegisterActiveObject\", hrReg);\r\n\r\n    ATL::CComPtr<IUnknown> unk;\r\n    auto hrGet = rot->GetObject(mk, &unk);\r\n    ExitIfFailed(L\"IRunningObjectTable::GetObject\", hrGet);\r\n\r\n    std::cout << unk.IsEqualObject(&#038;obj) << std::endl;\r\n\r\n    RevokeActiveObject(reg, nullptr);\r\n  }\r\n  {\r\n    Hoge obj2;\r\n    DWORD reg;\r\n    auto hrReg = rot->Register(\r\n      ROTFLAGS_REGISTRATIONKEEPSALIVE, &obj2, mk, &reg);\r\n    ExitIfFailed(L\"RegisterActiveObject\", hrReg);\r\n\r\n    ATL::CComPtr<IUnknown> unk;\r\n    auto hrGet = GetActiveObject(CLSID_Hoge, nullptr, &unk);\r\n    ExitIfFailed(L\"GetActiveObject\", hrGet);\r\n\r\n    std::cout << unk.IsEqualObject(&#038;obj2) << std::endl;\r\n\r\n    rot->Revoke(reg);\r\n  }\r\n  std::quick_exit(0);\r\n}\r\n<\/pre>\n<p>\u30af\u30e9\u30b9\u30e2\u30cb\u30ab\u30fc\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3068\u601d\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u305d\u306e\u4e88\u60f3\u306f\u5916\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RegisterActiveObject\u95a2\u6570\u304cIRunningObjectTable\u3092\u3069\u3046\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,10,12],"tags":[320],"class_list":["post-886","post","type-post","status-publish","format-standard","hentry","category-cpp","category-com","category-vc","tag-com-moniker"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>RegisterActiveObject\u3068ROT - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d<\/title>\n<meta name=\"description\" content=\"RegisterActiveObject\u95a2\u6570\u304cIRunningObjectTable\u3092\u3069\u3046\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RegisterActiveObject\u3068ROT - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d\" \/>\n<meta property=\"og:description\" content=\"RegisterActiveObject\u95a2\u6570\u304cIRunningObjectTable\u3092\u3069\u3046\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/\" \/>\n<meta property=\"og:site_name\" content=\"\u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ysk.noh\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-21T19:11:10+00:00\" \/>\n<meta name=\"author\" content=\"egtra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@egtra\" \/>\n<meta name=\"twitter:site\" content=\"@egtra\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"egtra\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"1\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/\",\"url\":\"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/\",\"name\":\"RegisterActiveObject\u3068ROT - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d\",\"isPartOf\":{\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/#website\"},\"datePublished\":\"2016-05-21T19:11:10+00:00\",\"dateModified\":\"2016-05-21T19:11:10+00:00\",\"author\":{\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/#\/schema\/person\/8de756b2ff20b964f64594dfe8f18164\"},\"description\":\"RegisterActiveObject\u95a2\u6570\u304cIRunningObjectTable\u3092\u3069\u3046\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u30db\u30fc\u30e0\",\"item\":\"https:\/\/dev.activebasic.com\/egtra\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"RegisterActiveObject\u3068ROT\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/#website\",\"url\":\"https:\/\/dev.activebasic.com\/egtra\/\",\"name\":\"\u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d\",\"description\":\"\u982d\u306e\u4e2d\u306e\u304b\u3051\u3089\u3002ActiveBasic\u3092\u4e2d\u5fc3\u306b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u8a71\u3092\u307c\u3061\u307c\u3061\u3068\u3002\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dev.activebasic.com\/egtra\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/#\/schema\/person\/8de756b2ff20b964f64594dfe8f18164\",\"name\":\"egtra\",\"sameAs\":[\"https:\/\/x.com\/egtra\"],\"url\":\"https:\/\/dev.activebasic.com\/egtra\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"RegisterActiveObject\u3068ROT - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","description":"RegisterActiveObject\u95a2\u6570\u304cIRunningObjectTable\u3092\u3069\u3046\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/","og_locale":"ja_JP","og_type":"article","og_title":"RegisterActiveObject\u3068ROT - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","og_description":"RegisterActiveObject\u95a2\u6570\u304cIRunningObjectTable\u3092\u3069\u3046\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002","og_url":"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/","og_site_name":"\u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","article_publisher":"https:\/\/www.facebook.com\/ysk.noh","article_published_time":"2016-05-21T19:11:10+00:00","author":"egtra","twitter_card":"summary_large_image","twitter_creator":"@egtra","twitter_site":"@egtra","twitter_misc":{"\u57f7\u7b46\u8005":"egtra","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"1\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/","url":"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/","name":"RegisterActiveObject\u3068ROT - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","isPartOf":{"@id":"https:\/\/dev.activebasic.com\/egtra\/#website"},"datePublished":"2016-05-21T19:11:10+00:00","dateModified":"2016-05-21T19:11:10+00:00","author":{"@id":"https:\/\/dev.activebasic.com\/egtra\/#\/schema\/person\/8de756b2ff20b964f64594dfe8f18164"},"description":"RegisterActiveObject\u95a2\u6570\u304cIRunningObjectTable\u3092\u3069\u3046\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002","breadcrumb":{"@id":"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dev.activebasic.com\/egtra\/2016\/05\/22\/886\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u30db\u30fc\u30e0","item":"https:\/\/dev.activebasic.com\/egtra\/"},{"@type":"ListItem","position":2,"name":"RegisterActiveObject\u3068ROT"}]},{"@type":"WebSite","@id":"https:\/\/dev.activebasic.com\/egtra\/#website","url":"https:\/\/dev.activebasic.com\/egtra\/","name":"\u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","description":"\u982d\u306e\u4e2d\u306e\u304b\u3051\u3089\u3002ActiveBasic\u3092\u4e2d\u5fc3\u306b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u8a71\u3092\u307c\u3061\u307c\u3061\u3068\u3002","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dev.activebasic.com\/egtra\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/dev.activebasic.com\/egtra\/#\/schema\/person\/8de756b2ff20b964f64594dfe8f18164","name":"egtra","sameAs":["https:\/\/x.com\/egtra"],"url":"https:\/\/dev.activebasic.com\/egtra\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/posts\/886"}],"collection":[{"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/comments?post=886"}],"version-history":[{"count":0,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/posts\/886\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/media?parent=886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/categories?post=886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/tags?post=886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}