我不确定PowerShell是否可以做到这一点。
但基本上我有一个Windows Forms程序,用于配置一个名为EO服务器的程序。EO服务器有一个应用程序接口,我引用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窗体应用程序中相同类型的调用?
发布于 2011-11-02 04:13:57
是的,您可以:
Add-Type -Path $customDll
$a = new-object custom.type
您可以像这样调用静态方法:
[custom.type]::method()
除了Add-Type,您还可以使用反射:
[Reflection.Assembly]::LoadFile($customDll)
(请注意,即使是上面的代码也在调用反射库和LoadFile静态方法。)
发布于 2011-11-02 04:09:56
请看博客帖子。如果您可以在.NET中与对象交互,那么您可能也可以在PowerShell中这样做。
发布于 2019-04-20 14:59:07
实际上,其他提供的解决方案对我不起作用,这里是一个完全适合我的替代方案:
$AssemblyPath = "C:\SomePath\SomeLIB.dll"
$bytes = [System.IO.File]::ReadAllBytes($AssemblyPath)
[System.Reflection.Assembly]::Load($bytes)
https://stackoverflow.com/questions/7972141
复制相似问题