【问题标题】:Run my third-party DLL file with PowerShell使用 PowerShell 运行我的第三方 DLL 文件
【发布时间】:2011-12-19 19:18:47
【问题描述】:

我不确定这是否可以使用 PowerShell。

但基本上我有一个Windows Forms 程序,它配置了一个名为 EO Server 的程序。 EO Server 有一个 API,我引用了 EOServerAPI.dll 来运行下面的代码。

using EOserverAPI;
...
private void myButton_Click(object sender, EventArgs e)
{
    String MDSConnString="Data Source=MSI;Initial Catalog=EOMDS;Integrated Security=True;";

    //Create the connection
    IEOMDSAPI myEOMDSAPI = EOMDSAPI.Create(MDSConnString);

    //Get JobID
    Guid myMasterJobID = myEOMDSAPI.GetJobID("myJobRocks");
}

是否可以与 API DLL 文件交互并进行与在 Windows 窗体应用程序中相同类型的调用?

【问题讨论】:

    标签: powershell powershell-2.0 powershell-remoting


    【解决方案1】:

    是的,您可以:

    Add-Type -Path $customDll
    $a = new-object custom.type
    

    你像这样调用一个静态方法:

    [custom.type]::method()
    

    除了Add-Type,你也可以使用反射:

    [Reflection.Assembly]::LoadFile($customDll)
    

    (请注意,即使上面是调用反射库和LoadFile静态方法。)

    【讨论】:

    • 我迷失了第二个陈述。 $a= new-object custom.type 我不知道怎么调用我的 custom.type 你能帮帮我吗?
    • @MicroSumol 类型是你的类的完全限定名(命名空间+类名)。例如。 A.B.C.ClassName
    【解决方案2】:

    看看博文Load a Custom DLL from PowerShell。如果您可以在 .NET 中与对象交互,那么您也可以在 PowerShell 中进行。

    【讨论】:

      【解决方案3】:

      c#dll

      Add-Type -Path $dllPath
      (new-object namespace.class)::Main() #Where namespace=dllnamespace, class=dllclass, Main()=dllstartvoid
      

      信息。获取命名空间和类

      $types = Add-Type -Path $dllPath -PassThru
      $types | ft fullname
      $types
      

      如果它不是“可执行” dll(获取/设置 dll),那么这是我所知道的最好的(不需要与示例 dll 创建相比):

      https://kazunposh.wordpress.com/2012/03/19/проверка-корректного-ввода-distinguished-name-в-скри/

      【讨论】:

        【解决方案4】:

        实际上,其他提供的解决方案对我不起作用,这是一个非常适合我的替代方案:

        $AssemblyPath = "C:\SomePath\SomeLIB.dll"
        $bytes = [System.IO.File]::ReadAllBytes($AssemblyPath)
        [System.Reflection.Assembly]::Load($bytes)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-08-29
          • 2014-05-02
          • 1970-01-01
          • 2012-12-08
          • 2010-10-04
          • 1970-01-01
          • 2014-07-10
          • 1970-01-01
          相关资源
          最近更新 更多