title: Running a function in DLL(.net) in PHP - Nothing seems to work
body: <p>Ok, I have gone through almost every question, PHP Manual and post around this issue all over the internet. Nothing seems to help.</p>
  
  <p>I'm working on a project that needs me to authenticate (or at least be able to lookup the UID for) different users in my organisation on an Active Directory. For connecting and authenticating, they have provided me with a dll file which has the functions necessary to authenticate. I need to use this dll file and the functions within to get my application working.</p>
  
  <p>Below are the different things I have tried so far along with errors for each.</p>
  
  <ol>
  <li><strong>Use <a href="http://php.net/manual/en/function.dl.php" rel="nofollow noreferrer">dl()</a> to load the DLL.</strong></li>
  </ol>
  
  <p>I tried using</p>
  
  <pre><code>dl('filename.dll');
  </code></pre>
  
  <p>and got the error</p>
  
  <pre><code>Call to undefined function dl() in C:\xampp\htdocs\OOP_curater\index.php on line 16
  </code></pre>
  
  <p>After looking around I came across <a href="https://stackoverflow.com/questions/16163525/call-to-undefined-function-dl">this</a> and <a href="https://stackoverflow.com/questions/12221650/php-5-3-enable-dl-not-enabling-dl">this</a> I realized it's no more supported.</p>
  
  <p>I then tried placing the dll in C:\xampp\php\ext and adding an extention line to php.ini. (Just for the heck of it) restarting php gave me an error message saying it's not a valid PHP extention.</p>
  
  <ol start="2">
  <li><strong>Tried using <a href="http://php.net/manual/en/book.com.php" rel="nofollow noreferrer">COM()</a></strong></li>
  </ol>
  
  <p>I then tried using </p>
  
  <pre><code>$action = new COM("ProjectName.FunctionName") or die ("Could not initialise MS Word object."); 
  </code></pre>
  
  <p>and got the following error</p>
  
  <pre><code>Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `ProjectName.FunctionName': Invalid syntax ' in C:\xampp\htdocs\OOP_curater\index.php:3 Stack trace: #0 C:\xampp\htdocs\OOP_curater\index.php(3): com-&gt;com('FBA_Provider1.a...') #1 {main} thrown in C:\xampp\htdocs\OOP_curater\index.php on line 3
  </code></pre>
  
  <p>Looking around got me to links similar to <a href="https://stackoverflow.com/questions/1955429/how-do-i-call-a-function-from-a-dll-from-php-on-windows">this</a>. I realized I need to register the DLL so tried</p>
  
  <pre><code>regsvr32 C:\xampp\htdocs\OOP_curater\filename.dll
  </code></pre>
  
  <p>and got the error </p>
  
  <pre><code>DllRegisterServer entry point was not found
  </code></pre>
  
  <p>I then tried</p>
  
  <pre><code>regsvr32 /i /n C:\xampp\htdocs\OOP_curater\filename.dll
  </code></pre>
  
  <p>and got a "DLL Install was not found" error.</p>
  
  <p>I must admit, I'm still not sure if I got the (Projectname.FunctionName) part right, i really could not understand most of the documentation around this topic.</p>
  
  <ol start="3">
  <li><strong>Tried using <a href="http://php.net/manual/en/class.dotnet.php" rel="nofollow noreferrer">DOTNET()</a></strong></li>
  </ol>
  
  <p>I then tried the following code</p>
  
  <pre><code>$comobj = new DOTNET("projectname", "projectname.function");
  </code></pre>
  
  <p>and got this error</p>
  
  <pre><code>Fatal error: Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [CreateInstance] [0x80070002] The system cannot find the file specified. ' in C:\xampp\htdocs\OOP_curater\index.php:21 Stack trace: #0 C:\xampp\htdocs\OOP_curater\index.php(21): dotnet-&gt;dotnet('ProjectName', 'Function') #1 {main} thrown in C:\xampp\htdocs\OOP_curater\index.php on line 21
  </code></pre>
  
  <p>I now have the following questions with regards to loading a DLL for PHP</p>
  
  <p><strong>What is the best way to load a DLL where:</strong></p>
  
  <p>a. It is not really a PHP function</p>
  
  <p>b. The source is not available</p>
  
  <p>c. It cannot be registered (assuming due to the errors above)</p>
  
  <p>d. It cannot be recompiled to be a PHP Extension / Register able </p>
  
  <p><strong>Few Things to Note</strong></p>
  
  <ol>
  <li>The setup is currently on XXAMP for development and testing.</li>
  <li>I do not have admin rights, but can arrange for it if necessary.</li>
  <li>Production environment would be on a windows server running IIS.</li>
  </ol>
  
  <p>I have very little knowledge in .net and Active Directory which is why I find this even tougher to handle. Also given the length of the question, hope I didn't miss out on anything important. Do let me know if you need more info.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I was able to decompile the DLL using <a href="http://www.red-gate.com/products/dotnet-development/reflector/" rel="nofollow noreferrer">Reflector</a>, and now have the source code and access to Microsoft Visual Studio for Applications 2.0. Incase you need me to make changed to the DLL itself.</p>
  
  <p>Also I tried building it with the "make visible to com" option checked but still got the same error with regsvr 32 and regasm.</p>