Xml 第三方Delphi DLL消耗
我已经用尽我的谷歌搜索选项 我们使用System Center Orchestrator在多个系统中自动创建用户。我们有一个第三方销售点应用程序,它以加密格式将用户密码存储在数据库中,用户的应用程序可以读取。对于自动插入用户数据库,我们需要能够插入加密密码,以便应用程序识别 他们不会向我们提供他们遵循的加密方法,但已经创建了一个DLL供我们使用,它是用Delphi编写的。它接受XML包装中传递的字符串,然后返回带有加密密码字符串的XML响应 从System Center Orchestrator的角度来看,使用此DLL的最佳方式是什么,请记住我自己或实现此功能的系统工程师以前从未做过类似的事情 任何建议都将不胜感激Xml 第三方Delphi DLL消耗,xml,delphi,dll,pinvoke,system-center,Xml,Delphi,Dll,Pinvoke,System Center,我已经用尽我的谷歌搜索选项 我们使用System Center Orchestrator在多个系统中自动创建用户。我们有一个第三方销售点应用程序,它以加密格式将用户密码存储在数据库中,用户的应用程序可以读取。对于自动插入用户数据库,我们需要能够插入加密密码,以便应用程序识别 他们不会向我们提供他们遵循的加密方法,但已经创建了一个DLL供我们使用,它是用Delphi编写的。它接受XML包装中传递的字符串,然后返回带有加密密码字符串的XML响应 从System Center Orchestrator
编辑 字符串将以以下格式传递给包含XML的可执行文件
<passwordEncryptionRequest>
<passwordIn>?</passwordIn>
<connectionDetails>
<serverName>?</serverName>
<serverInstance>?</serverInstance>
<userName>?</userName>
<connectionPassword>?</connectionPassword>
</connectionDetails>
</passwordEncryptionRequest>
<passwordEncryptionResponse>
<passwordOut>?</passwordOut>
<passwordEncryptionErrorResponse>
<errorDescription>?</errorDescription>
</passwordEncryptionErrorResponse>
</passwordEncryptionResponse>
使用(c#)的示例:
鉴于它现在实际上正确地实现了第三方dll(我检查了返回的字符串,结果很好),我将其标记为已回答。我现在将努力解决这些其他问题:)
谢谢大家的意见,我感谢你们的帮助
您好,Dan声明函数如下
function EncryptPassword(inputString: PWideChar; var outputString: PWideChar)
: wordbool; stdcall; external 'PasswordEncrypt.dll';
建造一个
inputstring := '<passwordEncryptionRequest>
<passwordIn>?</passwordIn>
<connectionDetails>
<serverName>?</serverName>
<serverInstance>?</serverInstance>
<userName>?</userName>
<connectionPassword>?</connectionPassword>
</connectionDetails>
</passwordEncryptionRequest>'
如果函数返回true,您将在outputString中获得一个xml字符串,并在tag中找到您的密码。这些开发人员提供的函数无法可靠地调用。当然,它不能使用提供的代码从C#调用。提供给您的函数声明如下:
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(string inputString,
out IntPtr outputString);
IntPtr outputStringPtr;
if (!EncryptPassword(inputString, out outputStringPtr))
// handle error
string outputString = Marshal.PtrToStringUni(outputStringPtr);
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
var
output: UnicodeString;
begin
output := InternalEncryptPassword(string(intputString));
outputString := PWideChar(output);
Result := True;
end;
function EncryptPassword(inputString: WideString;
out outputString: WideString): LongBool; stdcall;
begin
outputString := InternalEncryptPassword(intputString);
Result := True;
end;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(
[MarshalAs(UnmanagedType.BStr)]
string inputString,
[MarshalAs(UnmanagedType.BStr)]
out string outputString
);
string outputString;
if (!EncryptPassword(inputString, out outputString))
// handle error
返回值实际上应该是LongBool
,但这并不重要
主要问题是第二个参数。这需要Delphi代码分配一个字符串,并在outputString
中返回指向该字符串的指针。调用代码无法释放该字符串。可以调用函数的C代码如下所示:
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(string inputString,
out IntPtr outputString);
IntPtr outputStringPtr;
if (!EncryptPassword(inputString, out outputStringPtr))
// handle error
string outputString = Marshal.PtrToStringUni(outputStringPtr);
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
var
output: UnicodeString;
begin
output := InternalEncryptPassword(string(intputString));
outputString := PWideChar(output);
Result := True;
end;
function EncryptPassword(inputString: WideString;
out outputString: WideString): LongBool; stdcall;
begin
outputString := InternalEncryptPassword(intputString);
Result := True;
end;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(
[MarshalAs(UnmanagedType.BStr)]
string inputString,
[MarshalAs(UnmanagedType.BStr)]
out string outputString
);
string outputString;
if (!EncryptPassword(inputString, out outputString))
// handle error
你可以这样称呼它:
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(string inputString,
out IntPtr outputString);
IntPtr outputStringPtr;
if (!EncryptPassword(inputString, out outputStringPtr))
// handle error
string outputString = Marshal.PtrToStringUni(outputStringPtr);
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
var
output: UnicodeString;
begin
output := InternalEncryptPassword(string(intputString));
outputString := PWideChar(output);
Result := True;
end;
function EncryptPassword(inputString: WideString;
out outputString: WideString): LongBool; stdcall;
begin
outputString := InternalEncryptPassword(intputString);
Result := True;
end;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(
[MarshalAs(UnmanagedType.BStr)]
string inputString,
[MarshalAs(UnmanagedType.BStr)]
out string outputString
);
string outputString;
if (!EncryptPassword(inputString, out outputString))
// handle error
这使得outputStringPtr
分配的内存仍然无法释放
当然,即使这样,也假设Delphi开发人员分配内存的方式会比调用EncryptPassword
的时间更长。很可能他们实现了如下EncryptPassword
:
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(string inputString,
out IntPtr outputString);
IntPtr outputStringPtr;
if (!EncryptPassword(inputString, out outputStringPtr))
// handle error
string outputString = Marshal.PtrToStringUni(outputStringPtr);
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
var
output: UnicodeString;
begin
output := InternalEncryptPassword(string(intputString));
outputString := PWideChar(output);
Result := True;
end;
function EncryptPassword(inputString: WideString;
out outputString: WideString): LongBool; stdcall;
begin
outputString := InternalEncryptPassword(intputString);
Result := True;
end;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(
[MarshalAs(UnmanagedType.BStr)]
string inputString,
[MarshalAs(UnmanagedType.BStr)]
out string outputString
);
string outputString;
if (!EncryptPassword(inputString, out outputString))
// handle error
此函数用于在outputString
返回时释放其指向的内存
因此,底线是,提供给您的代码不好。下面是它的外观:
function EncryptPassword(inputString: WideString;
out outputString: WideString): LongBool; stdcall;
该函数可以实现如下内容:
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(string inputString,
out IntPtr outputString);
IntPtr outputStringPtr;
if (!EncryptPassword(inputString, out outputStringPtr))
// handle error
string outputString = Marshal.PtrToStringUni(outputStringPtr);
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
var
output: UnicodeString;
begin
output := InternalEncryptPassword(string(intputString));
outputString := PWideChar(output);
Result := True;
end;
function EncryptPassword(inputString: WideString;
out outputString: WideString): LongBool; stdcall;
begin
outputString := InternalEncryptPassword(intputString);
Result := True;
end;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(
[MarshalAs(UnmanagedType.BStr)]
string inputString,
[MarshalAs(UnmanagedType.BStr)]
out string outputString
);
string outputString;
if (!EncryptPassword(inputString, out outputString))
// handle error
在C#一侧,它看起来像这样:
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(string inputString,
out IntPtr outputString);
IntPtr outputStringPtr;
if (!EncryptPassword(inputString, out outputStringPtr))
// handle error
string outputString = Marshal.PtrToStringUni(outputStringPtr);
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
var
output: UnicodeString;
begin
output := InternalEncryptPassword(string(intputString));
outputString := PWideChar(output);
Result := True;
end;
function EncryptPassword(inputString: WideString;
out outputString: WideString): LongBool; stdcall;
begin
outputString := InternalEncryptPassword(intputString);
Result := True;
end;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(
[MarshalAs(UnmanagedType.BStr)]
string inputString,
[MarshalAs(UnmanagedType.BStr)]
out string outputString
);
string outputString;
if (!EncryptPassword(inputString, out outputString))
// handle error
这样称呼它:
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(string inputString,
out IntPtr outputString);
IntPtr outputStringPtr;
if (!EncryptPassword(inputString, out outputStringPtr))
// handle error
string outputString = Marshal.PtrToStringUni(outputStringPtr);
function EncryptPassword(inputString: PWideChar;
var outputString: PWideChar): WordBool; stdcall;
var
output: UnicodeString;
begin
output := InternalEncryptPassword(string(intputString));
outputString := PWideChar(output);
Result := True;
end;
function EncryptPassword(inputString: WideString;
out outputString: WideString): LongBool; stdcall;
begin
outputString := InternalEncryptPassword(intputString);
Result := True;
end;
[DllImport("PasswordEncrypt.dll", CharSet = CharSet.Unicode)]
private static extern bool EncryptPassword(
[MarshalAs(UnmanagedType.BStr)]
string inputString,
[MarshalAs(UnmanagedType.BStr)]
out string outputString
);
string outputString;
if (!EncryptPassword(inputString, out outputString))
// handle error
您没有提供有关他们提供给您的DLL、XML包装器或它返回的XML响应的任何信息。我们应该如何帮助别人?调用他们提供的DLL的已发布API是什么?(DLL的函数定义,通常用C表示。它通常在C头文件(something.h)中提供,但必须至少在文档中提供。)请发布该头文件中的函数定义,或他们提供的文档中的文本引用。否则,这里没有足够的信息来帮助您,您可能会被转介到供应商支持。嗨,Ken。符合其提供的功能规范的XML参数如下:;字符串将以以下格式传递给包含XML的可执行文件:?将从包含XML的可执行文件返回以下格式的字符串?我正在通读文档的其余部分,但它是非常简单的,没有提供任何关于您的问题的信息,请在那里提供这些信息,这些信息可以正确格式化,并且随时可用。要想理解它,很难费力地浏览评论表格中的所有杂乱无章的内容。谢谢。询问者正在尝试使用C#使用Delphi DLL。即使在Delphi中,上述代码也可能失败。感谢David的详细回复。我会按照你的建议去实施,看看会怎么样!我的时区可能要到今天下午,但我会尽快给出反馈。干杯但是请记住,我的回答指出,很可能您需要其他开发人员来修复他们的Delphi代码。实现大部分是有效的。当我在调试模式下运行时,我会按需要获取输出字符串。但是,在正常执行期间,我会遇到应用程序崩溃(stackhash)。我会说是DEP造成的,但我暂时禁用了它,仍然得到了错误。我相信Delphi DLL从根本上被破坏了。我不相信你能做的任何事都能解决它。你需要回到最初的开发者那里。让他们看看我的答案。