title: Chrome native messaging on windows
body: <p>I think it was already waiting for answer, but not sure: <a href="https://stackoverflow.com/questions/21326629/native-app-does-not-work-in-chrome-extension?rq=1%20"> <a href="https://stackoverflow.com/questions/21326629/native-app-does-not-work-in-chrome-extension?rq=1">Native app does not work in Chrome extension</a> </a>
  <br>
  On Linux, it works fine, but on Windows 7 and 8 I always get an error "<em>Specified native messaging host not found</em>".</p>
  
  <p>This is my <strong>registry</strong> (I've already tried with double backslash and with HKEY_LOCAL_MACHINE):
  <br></p>
  
  <pre><code>REG ADD HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.google.chrome.example.echo /ve /d C:\Users\Chriss\Desktop\nativeMessaging\host\com.google.chrome.example.echo-win.json
  </code></pre>
  
  <p><br>
  <strong>manifest.json</strong>:<br></p>
  
  <pre><code>{
      // Extension ID: knldjmfmopnpolahpmmgbagdohdnhkik
      "key":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDcBHwzDvyBQ6bDppkIs9MP4ksKqCMyXQ/A52JivHZKh4YO/9vJsT3oaYhSpDCE9RPocOEQvwsHsFReW2nUEc6OLLyoCFFxIb7KkLGsmfakkut/fFdNJYh0xOTbSN8YvLWcqph09XAY2Y/f0AL7vfO1cuCqtkMt8hFrBGWxDdf9CQIDAQAB",
      "name": "Native Messaging Example",
      "version": "1.0",
      "manifest_version": 2,
      "description": "Send a message to a native application.",
      "browser_action": {
      "default_title": "Test Extension",
      "default_popup": "main.html"
      },
      "icons": {
      "128": "icon-128.png"
      },
      "permissions": [
      "nativeMessaging"
      ]
  }
  </code></pre>
  
  <p><br>
  <strong>com.google.chrome.example.echo-win.json</strong>:<br></p>
  
  <pre><code>{
      "name": "com.google.chrome.example.echo",
      "description": "Chrome Native Messaging API Example Host",
      "path": "C:\Users\Chriss\Desktop\nativeMessaging\host\native-messaging-example-host.exe",
      "type": "stdio",
      "allowed_origins": [
      "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"
      ]
  }
  </code></pre>
  
  <p><br>
  <strong>native-messaging-example-host.exe</strong>:<br></p>
  
  <pre><code>int main(int argc, char* argv[]) {
      // Define our message
      std::string message = "{\"text\": \"This is a response message\"}";
      // Collect the length of the message
      unsigned int len = message.length();
      // We need to send the 4 bytes of length information
      std::cout 
          &lt;&lt; char(((len &gt;&gt; 0) &amp; 0xFF))
          &lt;&lt; char(((len &gt;&gt; 8) &amp; 0xFF))
          &lt;&lt; char(((len &gt;&gt; 16) &amp; 0xFF))
          &lt;&lt; char(((len &gt;&gt; 24) &amp; 0xFF));
      // Now we can output our message
      std::cout &lt;&lt; message;
      return 0;
  }
  </code></pre>
  
  <p><br>
  <strong>JS snippet</strong>(it is from <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/nativeMessaging/app/main.js?revision=228976" rel="nofollow noreferrer">http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/nativeMessaging/app/main.js?revision=228976</a> ):<br></p>
  
  <pre><code>function connect() {
      var hostName = "com.google.chrome.example.echo";
      appendMessage("Connecting to native messaging host &lt;b&gt;" + hostName + "&lt;/b&gt;")
      port = chrome.runtime.connectNative(hostName);
      port.onMessage.addListener(onNativeMessage);
      port.onDisconnect.addListener(onDisconnected);
      updateUiState();
  }
  </code></pre>
  
  <p>I cannot find out what is the problem. Where is my fault?</p>
  
  <p><strong>update</strong><br>
  After monitoring the registries with Procces Monitor. I found that the chrome.exe searches for the key in the 64bit keys. Now as I can see there's no missing relevant registry key, but I still get the error.</p>