title: RDP Dynamic Virtual Channels - Creating multiple Listeners
body: <p>I have recently began working with Dynamic Virtual Channels.</p>
  
  <p><a href="https://docs.microsoft.com/en-us/windows/desktop/termserv/dvc-implementation-details" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/desktop/termserv/dvc-implementation-details</a></p>
  
  <p>I have used Static channels for a long time and was able to develop a single plugin that could listen on several channels.</p>
  
  <p>My problem is I am not able to get the Dynamic Virtual Channels to work with multiple listeners. I need to use DVCs to solve some concurrency issues I am having with static channels.</p>
  
  <p>Here is my Initialize method for a single channel:</p>
  
  <pre class="lang-c++ prettyprint-override"><code>HRESULT DVCPlugin::Initialize(__in IWTSVirtualChannelManager *pChannelMgr)
  {
      HRESULT hr;
  
      CComObject&lt;ListenerCallback&gt; *pListenerCallback;
      CComPtr&lt;ListenerCallback&gt; ptrListenerCallback;
      CComPtr&lt;IWTSListener&gt; ptrListener;
  
      // Create an instance of the DVCPlugin object.
      hr = CComObject&lt;ListenerCallback&gt;::CreateInstance(&amp;pListenerCallback);
      ptrListenerCallback = pListenerCallback;
  
      // Attach the callback to the endpoint.
      hr = pChannelMgr-&gt;CreateListener(
          DVC_CHANNEL,
          0,
          (ListenerCallback*)ptrListenerCallback,
          &amp;ptrListener);
  
      if (hr == S_OK) {
          MessageBox(NULL, L"DVC plugin is enabled!", L"Info...", MB_OK | MB_ICONWARNING);
      }
      else {
          MessageBox(NULL, L"DVC plugin initialize failure!", L"Info...", MB_OK | MB_ICONWARNING);
      }
  
      return hr;
  }
  </code></pre>
  
  <p>This works perfect for a SINGLE channel. When I try to add additional listeners, only the LAST one will be active. Anyone know how to add an additional channel to the initialize method?</p>
  
  <p>My code is based on this:
  <a href="https://docs.microsoft.com/en-us/windows/desktop/termserv/dvc-client-plug-in-example" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/desktop/termserv/dvc-client-plug-in-example</a></p>