title: Creating .Net Wrappers for Windows API and COM DLLs
body: <p>Let me start by saying that I don't know what I don't know at this point, so rather than specific answers, I'm also looking for better questions to ask, I think.  My .Net/C# is solid enough, and my C/C++ is meh.</p>
  
  <p>Lately, I'm finding that there are no libraries in the standard .Net framework to accomplish certain tasks, and while it's easy enough to download a third party library, I'd like to understand how to do it myself if one doesn't already exist.  </p>
  
  <p>In one recent case, I need to deal with MIDI in windows at a relatively low-level, and I accidentally found out that "winmm.dll" is the library I'll need to use by downloading a .net wrapper for MIDI and browsing through the source.  I understand that I'll have to make a wrapper class and do the whole P/Invoke thing to make that happen.</p>
  
  <p>The next thing I did was to search for documentation on the Windows API to figure out what was going on in the mystery box of "winmm.dll," and to my delight, there was a whole Windows SDK that I was able to download and read through.  I went through the "getting started" section of "Windows Development" which covered some of the basics via C++.  It talked a bit about COM, windows header files, and I know enough C++ to get the gist.</p>
  
  <p>Now, I need help connecting the dots on a few issues:</p>
  
  <p>1) The Windows SDK, so far, seems to suggest that I want to program to specific header files rather than the dlls themselves, but the .net wrappers I've found typically point to a specific .dll rather that a header file...</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Returns the number of MIDI input devices on this system.
  /// &lt;/summary&gt;
  /// Win32 docs: http://msdn.microsoft.com/en-us/library/ms711608(VS.85).aspx
  [DllImport("winmm.dll", SetLastError = true)]
  public static extern UInt32 midiInGetNumDevs();
  </code></pre>
  
  <p>I was under the impression that a header file and DLL needed to be in the same folder, but the windows SDK includes a folder with all the windows header files, and no DLLs (I'm guessing the registry comes into play here for mapping to specific libraries?)?  How do those header files eventually get mapped to actual libraries, and why does it seem like I don't even need to deal with header files to create a .Net wrapper?</p>
  
  <p>2) I can't seem to find documentation on winmm.dll, but I have found references to the functions I'll likely need in the "Windows API" list in the Windows SDK, and I'm pretty sure that the code for those functions are in winmm.dll.  How do I find the documentation for the specific libraries I'll need to begin creating my wrapper?  If I didn't know that I was going to need winmm.dll to access windows MIDI functionality, how could I have figured that out myself?</p>
  
  <p>3) Some DLLs are COM, some are plain windows DLLs, some are .net DLLs... how can I tell the different going forward?  It seems that creating wrappers for the former two would require a different approach.</p>
  
  <p>4) There is no page on MSDN for "Winmm.dll" listing all of its API, and I assume there's a good and practical reason for that, but I'm not sure what it is?  I'm used to .Net land where I can figure out what a library does and how to use it almost without effort.</p>
  
  <p>Thanks in advance for any insights.</p>