15

Hello I want to scan audio-video files and store their metadata in a database using php. I found this Command-line wrapper that uses TagLib.dll compiled by banshee developpers to do the job. It's works fine but it limited by the functions implemented. I want to access directly to the dll methods via PHP.

In PHP we have a function (DOTNET) that allows me to instantiate a class from a .Net assembly and call its methods and access its properties like this :

/*$obj = new DOTNET("assembly", "classname");*/  

$stack = new DOTNET("mscorlib", "System.Collections.Stack");
$stack->Push(".Net");
$stack->Push("Hello ");
echo $stack->Pop() . $stack->Pop();

//Returns string(10) "Hello .Net";

Here is the Taglib# project sources in github

I saw many questions relatives to PHP-DLL-COM and there is some recommendations :

  • Make the dll comVisible;
  • Register the dll with regsvr32;
  • Use a module definition file similar to

;

;

DESCRIPTION     "Simple COM object"

EXPORTS
                DllGetClassObject       PRIVATE
                DllCanUnloadNow         PRIVATE
                DllRegisterServer       PRIVATE
                DllUnregisterServer     PRIVATE

My question is : How can I build the DLL and use its method via PHP ?

My config :

  • OS

    Windows Server 2012 R2 Standard Edition i586

  • Apache :

    Apache/2.2.21 (Win32) DAV/2 PHP/5.4.42 mod_ssl/2.2.21 OpenSSL/0.9.8r

  • PHP

    PHP Version : 5.4.42
    Arch : x86
    Compiler : MSVC9 (Visual C++ 2008)
    COM support : enabled
    DCOM support : disabled
    .Net support enabled

  • Microsoft Visual Studio 2013

e-Learner
  • 517
  • 1
  • 4
  • 15
  • Duplicate answers question asked in the title... But body of the post asks completely different question. Duplicate is possible not what you are looking for - please make sure your post and title agree on what you actually have problem with and comment so I (or someone else) can re-open it if necessary. – Alexei Levenkov Jul 17 '15 at 15:20
  • Reopened as you are *not* looking for how to make assembly COM-visible in general and instead need step-by-step instructions for particular library. Warning: the question in current form probably will be closed later as "too broad" or "looking for library/off-site resources" - so consider clarifying what particular issue you are facing when followed approaches you've listed in the post. – Alexei Levenkov Jul 17 '15 at 15:36

2 Answers2

1

Give the following steps a try:

  1. Download taglib source code from github
  2. Remove the ApplicationIcon tag from the .csproj file and open .sln in Visual Studio
  3. Unload the test project (you don't need to build this)
  4. Right-click on taglib-sharp project --> properties --> build --> enable 'Register for COM interop'. Also clear the conditional compilation symbols textbox so that you don't have to bother with downloading SharpZipLib for now.
  5. Observe #1: in project properties --> Application --> Assembly information --> 'Make assembly COM visible' is checked
  6. Observe #2: in project properties --> Application --> target framework is set to 3.5 (make sure you leave it as that)
  7. Build the project (F6)
  8. Read the contents of the output window to see some warnings

Now that you have src\taglib-sharp.dll you need to register it into the global assembly cache in order for the DOTNET class to find it. See PHP DOTNET hell for details if you are not familiar with this.

If all is good, you can get yourself a copy of SharpZipLib, and reenter the HAVE_SHARPZIPLIB conditional compilation symbol --> rebuild --> redeploy to GAC --> and be a happy man! :)

Community
  • 1
  • 1
  • +70 I Have Successfully build the DLL. No more time to test it with PHP. When done I'll come back to give you results. Thanks ! – e-Learner Jul 27 '15 at 10:16
1

You may compile you DLL with .NET Framework 3.5 if not, PHP do not be able to load it via DOTNET class.

Download .NET 3.5

Ellen
  • 11
  • 3