title: Is there a way to pass an OCX control reference out from a Visual Basic 6 activeX dll via COM interop?
body: <p>I stumbled upon this while trying to build an <code>ActiveX dll</code> from an old (but still maintained) <code>VB6</code> <code>exe project</code>(*) sources in order to perform some testing via <code>COM / NET</code> interop.</p>
  
  <p><b>
  The (desired) use case is:</p>
  
  <ol>
  <li>Take a <code>VB6</code> class with public methods taking or returning some control (for example <code>CommonDialog</code>) reference</li>
  <li>Compile this class into an ActiveX dll</li>
  <li>Create an instance of this class via COM interop from .NET and correctly call its methods</li>
  </ol>
  
  <p></b></p>
  
  <p>In short, the first problem is that having something like</p>
  
  <pre><code>Public Function bad_dlg() As CommonDialog
     Set bad_dlg = Nothing
  End Function
  </code></pre>
  
  <p>in a Visual Basic 6 <code>ActiveX dll</code>'s class file makes the compilation (* *) fail with the following error:</p>
  
  <p><i>"Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types"</i></p>
  
  <p><b>
  Hence, the question is:</p>
  
  <ol>
  <li>Is it really impossible to have something like above compile and run properly?</li>
  <li>[IF NOT] Suppose, I change everything to return and receive instances of <code>VB6</code> <code>Object</code> type -- how can I work with such an instance from .Net (call specific methods, etc)</li>
  </ol>
  
  <p></b></p>
  
  <p>(*) -- not an <code>ActiveX exe</code>, just an "ordinary" one</p>
  
  <p>(* *) provided that appropriate <code>.ocx</code> ("Microsoft Common Dialog Control 6.0 (SP6)", C:\Windows\system32\ComDlg32.OCX) is referenced</p>
  
  <p>(* * *) the only one that I have found is <a href="http://forums.devx.com/archive/index.php/t-64253.html" rel="nofollow"><i>Passing control Ref to dll</i></a></p>