title: Using Win32::API to accessing the methods of a DLL in Perl
body: <p>I have in my possession a Microsoft Powershell script which examines all the files in a folded ending in .wtv (Windows Media Center recorded TV programmes), extracts some metadata (using a DLL called "Toub.MediaCenter.Dvrms.dll") and then writes it to stdout:</p>
  
  <pre><code>[void][System.Reflection.Assembly]::LoadFile("C:\Toub.MediaCenter.Dvrms.dll")
  
  # Get all files ending in .wtv
  
  foreach ($file in gci "*.wtv")
  {
    $wtv = New-Object Toub.Mediacenter.Dvrms.Metadata.DvrmsMetadataEditor($file)
    $attrlist = $wtv.GetAttributes()
  
    # Extract the Title and Description from the recorded programme
  
    $t = $attrlist["Title"].value
    $d = $attrlist["WM/SubTitleDescription"].value
  
    # Print them to STDOUT
  
    "$t"
    "$d"
  }
  </code></pre>
  
  <p>At the moment, I run this from a Perl script and then parse the results. It works, but is messy and I'd like to drop the powershell part and do it entirely within Perl.</p>
  
  <p>However, I have absolutely no idea how to link to a DLL so that I can call <strong>GetAttributes</strong> method on a file and then extract the values of <strong>Title</strong> and <strong>WM/SubTitleDescription</strong>.</p>
  
  <p>I was pointed to using <strong>Win32::API</strong>, but I have no idea what the name of the library from which I want to import the function nor do I know the C prototype of the function.</p>
  
  <p>As such, my code grinds to a halt because I'm not really sure what I should be doing with Win32::API. My (very basic) stub looks like this:</p>
  
  <pre><code>use Win32::API;
  
  foreach my $file (glob("*.wtv"))
  {
    my $wtv = new Win32::API(...stuck here...);
  
    # Complete guesswork from here on...
  
    print $wtv-&gt;GetAttributes("Title") . "\n";
    print $wtv-&gt;GetAttributes("WM/SubTitleDescription") . "\n";
  }
  </code></pre>
  
  <p>I'm guessing it's probably obvious from the Powershell above on what I should be putting into the <strong>new Win32::API</strong> line and whether or not <strong>$wtv->GetAttributes</strong> is correct - but to be honest, I don't have a clue.</p>
  
  <p>Can someone please point me in the right direction?</p>