在 Perl 中使用 Win32::API 访问 DLL 的方法

发布于 2024-09-13 08:33:06 字数 1419 浏览 2 评论 0原文

我拥有一个 Microsoft Powershell 脚本,该脚本检查所有以 .wtv 结尾的折叠文件(Windows Media Center 录制的电视节目),提取一些元数据(使用名为“Toub.MediaCenter.Dvrms.dll”的 DLL),然后将其写入标准输出:

[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"
}

目前,我从 Perl 脚本运行它,然后解析结果。它可以工作,但是很混乱,我想放弃 powershell 部分并完全在 Perl 中完成。

但是,我完全不知道如何链接到 DLL,以便我可以在文件上调用 GetAttributes 方法,然后提取 TitleWM/ 的值副标题描述

有人指出我使用 Win32::API,但我不知道要从中导入该函数的库的名称,也不知道该函数的 C 原型。

因此,我的代码逐渐停止,因为我不太确定应该使用 Win32::API 做什么。我的(非常基本的)存根看起来像这样:

use Win32::API;

foreach my $file (glob("*.wtv"))
{
  my $wtv = new Win32::API(...stuck here...);

  # Complete guesswork from here on...

  print $wtv->GetAttributes("Title") . "\n";
  print $wtv->GetAttributes("WM/SubTitleDescription") . "\n";
}

我猜从上面的 Powershell 中可以明显看出我应该将什么放入 new Win32::API 行以及是否 $ wtv->GetAttributes 是正确的 - 但说实话,我不知道。

有人可以指出我正确的方向吗?

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:

[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"
}

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.

However, I have absolutely no idea how to link to a DLL so that I can call GetAttributes method on a file and then extract the values of Title and WM/SubTitleDescription.

I was pointed to using Win32::API, 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.

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:

use Win32::API;

foreach my $file (glob("*.wtv"))
{
  my $wtv = new Win32::API(...stuck here...);

  # Complete guesswork from here on...

  print $wtv->GetAttributes("Title") . "\n";
  print $wtv->GetAttributes("WM/SubTitleDescription") . "\n";
}

I'm guessing it's probably obvious from the Powershell above on what I should be putting into the new Win32::API line and whether or not $wtv->GetAttributes is correct - but to be honest, I don't have a clue.

Can someone please point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不念旧人 2024-09-20 08:33:06

看起来 power shell 脚本正在加载 .net Framework dll 而不是 C api dll,它使用的类 Toub.Mediacenter.Dvrms.Metadata.DvrmsMetadataEditor 很可能是在其中定义的。我知道活动状态对 Pearl 和 .net 之间的互操作性有一些支持。

我不知道您是否有重要的 Perl 代码库,或者这是否是您的知识所在,但是 power shell 完全能够处理您的解析需求,朝这个方向前进可能会更容易。

It looks like the power shell script is loading a .net framework dll not a C api dll the class it uses Toub.Mediacenter.Dvrms.Metadata.DvrmsMetadataEditor is most likely defined in there. I know there is some support from active state for interoperability between pearl and .net.

I don't know if you have a significant code base of perl or if that is were your knowledge lies, but power shell is perfectly able to handle your parsing needs it may be easier to go in that direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文