在Powershell中使用本机dll函数

时间:2015-08-18 07:24:39

标签: c# powershell dll

我正在使用原生dll函数:

int ReadDomainPassword ([in] char *user, [in] char *domain, [out] char *password)

我在powershell中导入它,如下所示:

int ReadDomainPassword (string user, string domain, StringBuilder password)

该函数返回1表示一切顺利,但当我检查 $ password 创建为New-Object System.Text.StringBuilder时,它的长度为零:(

如何将数据从extern函数传递到powershell变量?

P.S。:同时相同的C#代码运行良好,我做错了什么?

$member = @'
[DllImport(xxx.dll, CallingConvention=CallingConvention.Cdecl, EntryPoint="?ReadDomainPasswordA00ZH@@")]
public static extern ReadDomainPassword (string user, string domain, StringBuilder password);
'@
$method = Add-Type -MemberDefenition $member -Name "RandomName" -UsingNamespace "System.Text" -PassThru
$password = New-Object System.Text.StringBuilder(256);
$method.ReadDomainPassword("", "", $password);
$password.ToString(); #<-- nothing there :( (works in c#)

0 个答案:

没有答案