using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
/******************************
* 说明:delphi与C#互操作类
* 创建人:龚宇超
* 创建日期:2017-08-16
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
namespace Lskj.Util
{
///
/// delphi与C#互操作类
///
public sealed class DelphiHelper
{
[DllImport("user32.dll", EntryPoint = "SetParent")]
public static extern IntPtr SetParent(IntPtr hChild, IntPtr hParent);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
///
/// 说明:调用delphi库函数
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The path.
/// The path1.
/// The FRM caption.
/// The system parameter STR1.
/// The system parameter STR2.
/// The FRM showid.
/// The system parameter STR3.
/// System.Int32.
[DllImport("Lib/DelphiDll.dll")]
public static extern int Delphi_Call(StringBuilder Path, StringBuilder Path1, StringBuilder FrmCaption,StringBuilder SysParameterStr1, StringBuilder SysParameterStr2, int FrmShowid, StringBuilder SysParameterStr3);
///
/// 说明:初始化
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The con string.
/// System.Int32.
[DllImport("Lib/DelphiDll.dll")]
public static extern int Delphi_Init(StringBuilder ConStr);
///
/// 说明:设置delphi库调用参数
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The operator identifier.
/// The system identifier.
/// Name of the operator.
/// Name of the ws.
/// The skin path string.
/// System.Int32.
[DllImport("Lib/DelphiDll.dll")]
public static extern int Delphi_SetParams(int OperatorID, int systemID, StringBuilder OperatorName, StringBuilder WSName, StringBuilder SkinPathStr);
///
/// 说明:给调用delphi库的通用库设置主窗体句柄 CallingConvention = CallingConvention.StdCall)
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The main handle.
/// System.Int32.
[DllImport("Lib/DelphiDll.dll")]
public static extern int SetMainHandle(int MainHandle);
///
/// 说明:delphi调用c#库
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// Name of the DLL.
/// The parms.
/// System.Int32.
[DllImport("Lib/DelphiDll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int DelphiCallCSharpDll(StringBuilder DLLName, StringBuilder parms);
///
/// 说明:获取两个密码
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The validate code e.
/// Length of the code e.
/// The validate code t.
/// Length of the code t.
/// true if XXXX, false otherwise.
[DllImport("Lib/DelphiDll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern bool GetValidateCode(ref StringBuilder ValidateCodeE, ref int CodeELen, ref StringBuilder ValidateCodeT, ref int CodeTLen);
///
/// 说明:调用delphi库函数
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The library key.
/// System.Int32.
[DllImport("Lib/DelphiDll.dll")]
public static extern int FreeDll(StringBuilder libKey);
///
/// 说明:调用delphi库函数下载附件
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The dfile.
/// The HWND.
/// StringBuilder.
[DllImport("Lib/DelphiDll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern StringBuilder DownloadAttach(StringBuilder dfile, int hwnd);
///
/// 说明:调用delphi库
/// 创建人:龚宇超
/// 创建日期:2018-06-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The s path.
/// System.Int32.
public static int LoadDelphiDll(string sPath)
{
return LoadDelphiDll("lib/" + sPath, sPath, "", "", "", 0, "");
}
///
/// 说明:调用delphi库
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The s path.
/// The s path1.
/// The s FRM caption.
/// The s system parameter STR1.
/// The s system parameter STR2.
/// The FRM showid.
/// The s system parameter STR3.
/// System.Int32.
public static int LoadDelphiDll(string sPath, string sPath1, string sFrmCaption,string sSysParameterStr1, string sSysParameterStr2, int showId, string sSysParameterStr3)
{
int result = 0;
Cursor.Current = Cursors.WaitCursor;
try
{
StringBuilder path = new StringBuilder();
path.Append(sPath);
StringBuilder path1 = new StringBuilder();
path1.Append(sPath1);
StringBuilder caption = new StringBuilder();
caption.Append(sFrmCaption);
StringBuilder sps1 = new StringBuilder();
sps1.Append(sSysParameterStr1);
StringBuilder sps2 = new StringBuilder();
sps2.Append(sSysParameterStr2);
StringBuilder sps3 = new StringBuilder();
sps3.Append(sSysParameterStr3);
result = Delphi_Call(path, path1, caption, sps1, sps2, showId, sps3);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Cursor.Current = Cursors.Default;
}
return result;
}
}
}