title: Accessing DLL function from a PHP DLL
body: <p>Essentially what I have is this structure:</p>
  
  <p>PHP Application -> PHP Extension (in C++) -> DLL Library (C++)</p>
  
  <p>The DLL library calls functions inside itself, for example</p>
  
  <pre><code>int Library::FunctionA(){
         return Library::FunctionB + 4;
  }
  </code></pre>
  
  <p>The problem is, when I try and call Library::Function A from my PHP extension, php crashes. I guess this is because php cannot call functions inside the DLL library (it cannot call Library::FunctionB from within the library) and therefore crashes?</p>
  
  <p>The source code for the DLL Library is:</p>
  
  <pre><code>using namespace std;
  
  namespace PMDInfo
  {
  class PMDParser
  {
  public:
      static __declspec(dllexport) string GetVariants(string FileName);
      static __declspec(dllexport) streamoff GetOffset(string FileName,streamoff offset);
  };
  }
   namespace PMDInfo {
         streamoff PMDParser::GetOffset(string FileName,streamoff offset){
              ifstream file2(FileName.c_str(), ios::binary);
              file2.seekg(offset);
           return (streamoff)file2.get();
     }
  
      string PMDParser::GetVariants(string FileName){
                      char *buffer1[40];
          ifstream ReadPMD(FileName.c_str(), ios::binary);
          streamoff begin = GetOffset(FileName,pmd_variant_name_table);       offsets
          streamoff end   = PMDInfo::PMDParser::GetOffset(FileName,pmd_group_table);
          return itoa(begin-end,buffer1,10);
      }
  }
  </code></pre>
  
  <p>And the source code for the php extension:
      using namespace std;</p>
  
  <pre><code>namespace PMDInfo
  {
  class PMDParser
  {
  public:
      static __declspec(dllimport) string GetVariants(string FileName);
      static __declspec(dllimport) streamoff GetOffset(string FileName,streamoff offset);
  };
  }
  
  --- PHP EXTENSION initiation code in here, all works fine ---
  
  ZEND_FUNCTION(GetVariants)
  {   
  
  int title_len;
  char *title = "";
  
  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &amp;title, &amp;title_len) == FAILURE) {
      RETURN_NULL();
  }
  RETURN_STRING(PMDInfo::PMDParser::GetVariants(title).c_str(),1);
  </code></pre>
  
  <p>} </p>
  
  <p>The point at which the application crashes is in the dll library when calling GetOffset(FileName,pmd_variant_name_table);. Am I referencing the functions wrong or something, or is the DLL unable to call functions inside itself?</p>
  
  <p>If this still isn't very clear please say what isnt!
  Any ideas?</p>