title: How do I access functions from libsndfile-1.dll in MSVC?
body: <p>&nbsp;&nbsp;I'm having trouble getting libsndfile-1.dll to work in my MSVC project. I can load the library and retrieve the version string from the dll by calling <code>sf_command()</code> from my code. However, I can't seem to get <code>sf__open()</code> to return a SNDFILE pointer.</p>
  
  <p>I've also noticed that I can't get <code>fopen()</code> to return a FILE pointer either (maybe this is related, I think <code>sf_open()</code> uses <code>fopen()</code>!?).</p>
  
  <p>I'm pretty new to MSVC, C/C++ and windows in general so I'm probably missing something really obvious. </p>
  
  <p>My main.cpp looks like this:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  
  #include "sndfile.hh"
  
  // create some function pointers to point to the dll function addresses
  // I'm winging this a bit. hopefully it's right!? seems to work!
  typedef int (*SF_COMMAND)(SNDFILE*, int, void*, int); 
  typedef SNDFILE* (*SF_OPEN)(const char*, int, SF_INFO*); 
  
  int main()
  {
      // dll handle
      HINSTANCE hDLL = NULL;
  
      // create some vars to store the dll funcs in
      SF_COMMAND     sf_command;
      SF_OPEN        sf_open;
  
      // load the dll
      hDLL = LoadLibrary(L"libsndfile-1.dll");
  
      // check the dll loaded
      if( NULL == hDLL )
      {
          printf("Error, Could not load library \n");
          return 1;
      }
  
      // get the dll funcs
      sf_command = (SF_COMMAND)GetProcAddress(hDLL, "sf_command");
      sf_open = (SF_OPEN)GetProcAddress(hDLL, "sf_open");
  
      // check we got the funcs
      if(!(sf_command &amp;&amp; sf_open)){
          printf("Error exporting dll functions \n");
          return 2;
      }
  
      // all good so far!
      // try the first function
      char* version_string[sizeof(char*)*4];
      int res = sf_command(NULL, SFC_GET_LIB_VERSION, &amp;version_string, sizeof(version_string));
  
      if(res){
          // all good!
          printf("Version: %s \n", version_string);
      }
  
      // now try and create a SNDFILE pointer
      SF_INFO info;
      SNDFILE* sfp = sf_open("c:\\Godspeed.aif", SFM_READ, &amp;info);
  
      if(sfp){
          printf("Hurray! successfully opened the SNDFILE!! \n");
      }else{
          printf("Doh! couldn't open the SNDFILE!! \n");
          // Grr!!
          return 3;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The project builds and exits with code 3 (couldn't open the file! (I'm pretty sure the file is there!!)).</p>
  
  <p>When I run the exe the output is: <br />
  <code>Version: libsndfile-1.0.17</code> <br />
  <code>Doh! couldn't open the SNDFILE</code> <br /></p>
  
  <p>Does anyone have any suggestions as to where I'm going wrong?</p>
  
  <p>Many thanks, <br />
  Josh.</p>