高手请进,高分请教(100分),问题解决可以再给分!
.NET 调用DELPHI 编写的DLL时出现......
DLL中的一个函数为:
function WriteDemo(Pwd:Pchar):Longint;
DELPHI调用方法为缩写:
申明--
Function WriteDemo(Password :Pchar):Longint; far;external 'DEMO.dll' name 'WriteDemo';
调用--
procedure TForm1.Button4Click(Sender: TObject);
var
Password:Pchar;
IResult:Integer;
BEGIN
GetMem(Password,4);
Password[0] := Char($01);
Password[1] := Char($11);
Password[2] := Char($10);
Password[3] := Char($22);
IResult := WriteDemo( Password );
End
.Net调用方法缩写:
申明--
[DllImport("DEMO.dll",CharSet =CharSet.Ansi)]
public static extern int WriteDemo( byte[] bPwd );
或申明为
public static extern int WriteDemo( System.Text.StringBuilder strPwd );
调用1--
public static int PostBackDemo()
{
System.Text.StringBuilder strBl = new System.Text.StringBuilder("01111022");
return WriteDemo( strBl );
}
调用2--
public static int PostBackDemo()
{
byte[] by = new byte[];
by = System.Text.Encoding.Default.GetBytes( "01111022");
return WriteDemo( strBl );
}
以上两种方法调用都出错!出错问题主要是出现在pchar类型的转换问题,请高手指点如何解决.net调用DELPHI DELL 传PCHAR参数解决方法。
如查能提供完整的。NET调用DELPHI DLL方法最好,谢啦!