title: Preparing a Visual Basic DLL for C++ consumption
body: <p>According to <a href="https://msdn.microsoft.com/en-us/library/8etzzkb6.aspx" rel="nofollow noreferrer">this Microsoft page</a>, the #import directive can be used to generate C++ header files from a type library. I have used it sucessfully with 3rd party libraries.</p>
  
  <p>I am now trying to code a User Control in Visual Basic (using XAML) to be consumed in a C++ application. The idea is to have the control raise events that the application loop would then consume.</p>
  
  <p><strong>1) How can I embed a type library from Visual Basic?</strong> When I use the #import directive with the DLL generated in Visual Basic I get</p>
  
  <blockquote>
    <p>error C1083: Cannot open type library file: (dll path here) Error loading type library/DLL. (cpp filename here)</p>
  </blockquote>
  
  <p>Since the DLL path is correct (and it works when added as reference to another Visual Basic project), I am guessing the DLL is missing some sort of export information.</p>
  
  <p><strong>2) How can a User Control find the <code>HWND</code> of its parent?</strong>
  I would like to use it later to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms644944.aspx" rel="nofollow noreferrer">post a message</a>.</p>
  
  <hr>
  
  <p>I have found <a href="https://stackoverflow.com/q/3679967/2549876">this question</a> that asks something similar. In my case, I will create the DLL.</p>