C#调用Delphi编译的DLL函数库返回大文本数据
C#调用Delphi编译的DLL库获取大文数据
如果用PChar作为指针传递参数会丢失数据,之前做过测试,理想的方法是用StringBuilder对象分配一段内存区.
下面的代码是C#.NET枚举Novell网络中的对象(如用户/组/组织单元等).
API 函数定义:
LDAP_DLL_DelphiComplied.NovellGetObjects()
C#.NET实现:
DELPHI 实现:
扫一扫加作者微信
如果用PChar作为指针传递参数会丢失数据,之前做过测试,理想的方法是用StringBuilder对象分配一段内存区.
下面的代码是C#.NET枚举Novell网络中的对象(如用户/组/组织单元等).
API 函数定义:
LDAP_DLL_DelphiComplied.NovellGetObjects()
[DllImport(DLL_NAME, EntryPoint = "NovellGetObjects", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int NovellGetObjects(string NovellPath, string ClassName, StringBuilder ADestBuffer, int ADestSize);
public static extern int NovellGetObjects(string NovellPath, string ClassName, StringBuilder ADestBuffer, int ADestSize);
C#.NET实现:
/// <summary>
/// 获取Novell网对象
/// </summary>
/// <param name="NovellPath">有效路径.如: .mis.csframework.com 或 .xx.cn</param>
/// <param name="ClassName">取对象类型: Organizational Unit,Group,User </param>
/// <returns></returns>
public static DataTable NovellGetObjects(string NovellPath, string ClassName)
{
try
{
StringBuilder sb = new StringBuilder(100000);
int count = LDAP_DLL_DelphiComplied.NovellGetObjects(NovellPath, ClassName, sb, 100000);
return GetStringTable(sb.ToString());
}
catch
{
return null;
}
}
// 来源:www.CSFramework.com, C/S结构框架学习网
/// 获取Novell网对象
/// </summary>
/// <param name="NovellPath">有效路径.如: .mis.csframework.com 或 .xx.cn</param>
/// <param name="ClassName">取对象类型: Organizational Unit,Group,User </param>
/// <returns></returns>
public static DataTable NovellGetObjects(string NovellPath, string ClassName)
{
try
{
StringBuilder sb = new StringBuilder(100000);
int count = LDAP_DLL_DelphiComplied.NovellGetObjects(NovellPath, ClassName, sb, 100000);
return GetStringTable(sb.ToString());
}
catch
{
return null;
}
}
// 来源:www.CSFramework.com, C/S结构框架学习网
DELPHI 实现:
function NovellGetObjects(NovellPath: PChar; ClassName: PChar; ADestBuffer: PChar; ADestSize: Integer; only3: Integer): Integer; stdcall; export;
var S: string;
begin
S := DirTools.NovellGetObjects(NovellPath, ClassName, only3 = 1); //获取字符串
Move(S[1], ADestBuffer^, Min(ADestSize, Length(S) 1));
Result := Length(S);
end;
// 来源:www.CSFramework.com, C/S结构框架学习网
var S: string;
begin
S := DirTools.NovellGetObjects(NovellPath, ClassName, only3 = 1); //获取字符串
Move(S[1], ADestBuffer^, Min(ADestSize, Length(S) 1));
Result := Length(S);
end;
// 来源:www.CSFramework.com, C/S结构框架学习网
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网