[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate System.Int32 VCallback(IntPtr lparams, IntPtr handle);
#region Библиотека Cipherlab
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpCreate")]
static extern int CipherlabtcpCreate(ref IntPtr ptrtohandle);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpDestroy")]
static extern int CipherlabtcpDestroy(IntPtr handle);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpSetEventMessage")]
static extern int CipherlabtcpSetEventMessage(IntPtr handle, IntPtr hwnd, int messageid, IntPtr lparam);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpSetEventCallback")]
static extern int CipherlabtcpSetEventCallback(IntPtr handle, VCallback callbackfunc, IntPtr lparam);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpGetProperties")]
static extern int CipherlabtcpGetProperties(IntPtr handle, out int Port, out int SaveMethod, out int Debug);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpSetProperties")]
static extern int CipherlabtcpSetProperties(IntPtr handle, int Port, int SaveMethod, int Debug);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpGetLastError")]
static extern int CipherlabtcpGetLastError(IntPtr handle, out int lasterror);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpStart")]
static extern int CipherlabtcpStart(IntPtr handle);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", EntryPoint = "cipherlabtcpStop")]
static extern int CipherlabtcpStop(IntPtr handle);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", CharSet = CharSet.Unicode, EntryPoint = "cipherlabtcpGetSerialNumber")]
static extern int CipherlabtcpGetSerialNumber(IntPtr handle, IntPtr eventhandle, StringBuilder NumberTSD);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", CharSet = CharSet.Unicode, EntryPoint = "cipherlabtcpGetSerialNumberA")]
static extern int CipherlabtcpGetSerialNumberA(IntPtr handle, IntPtr eventhandle, StringBuilder NumberTSD);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", CharSet = CharSet.Unicode, EntryPoint = "cipherlabtcpGetEvent")]
static extern int CipherlabtcpGetEvent(IntPtr handle, IntPtr eventhandle, StringBuilder messagebuf);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", CharSet = CharSet.Unicode, EntryPoint = "cipherlabtcpGetData")]
static extern int CipherlabtcpGetData(IntPtr handle, IntPtr eventhandle, out int NumberDB, out int NumberForm, StringBuilder Field1, StringBuilder Field2, StringBuilder Field3, StringBuilder Field4, StringBuilder Field5, StringBuilder Field6, StringBuilder Field7, StringBuilder Field8);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", CharSet = CharSet.Unicode, EntryPoint = "cipherlabtcpAnswer")]
static extern int CipherlabtcpAnswer(IntPtr handle, IntPtr eventhandle, string OutField1, string OutField2, string OutField3, string OutField4, string OutField5, string OutField6, string OutField7, string OutField8, string NewRow, string NewForm);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", CharSet = CharSet.Unicode, EntryPoint = "cipherlabtcpSendMessage")]
static extern int CipherlabtcpSendMessage(IntPtr handle, string NumberTSD, string TextOfMessage);
[DllImport("CipherLabTCP8_x86_64_1_0_5_14.dll", CharSet = CharSet.Unicode, EntryPoint = "cipherlabtcpSendWarning")]
static extern int CipherlabtcpSendWarning(IntPtr handle, string NumberTSD, string TextOfMessage);
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
#endregion
static IntPtr m_server = IntPtr.Zero;
static readonly int m_port = 1024;
const int WM_APP = 0x8000;
const int MAXSNSIZE = 256;
const int MAXFIELDSIZE = 256;
readonly VCallback TSDCallBack = new VCallback(TSDCallbackFunc);
private static int TSDCallbackFunc(IntPtr lparams, IntPtr handle)
{
int res;
StringBuilder sbsn = new StringBuilder(MAXSNSIZE);
StringBuilder sbcmd = new StringBuilder(MAXSNSIZE);
res = CipherlabtcpGetEvent(m_server, handle, sbcmd);
string command = sbcmd.ToString();
res = CipherlabtcpGetSerialNumber(m_server, handle, sbsn);
string serialnumber = sbsn.ToString();
return 0;
}
// Кнопка запуска сервера
private void ButtonStartServer_Click(object sender, EventArgs e)
{
int res;
res = CipherlabtcpCreate(ref m_server);
res = CipherlabtcpSetEventCallback(m_server, TSDCallBack, IntPtr.Zero);
res = CipherlabtcpSetProperties(m_server, Global.m_port, 1, checkBoxDebug.Checked ? 1 : 0);
// Вот тут крашимся на версии либы 1.0.5.14, а на 1.0.5.11 всё норм!
res = CipherlabtcpStart(m_server);
}
|