// [10/24/2003] //主动请求Item的值 public unsafe string Request(string name) { IntPtr hszItem, hDDEData; int dwResult = 0; int dwLength = 0; if (name != null && hconvCurrent != IntPtr.Zero) { hszItem = Ddeml.DdeCreateStringHandle(dwDDEInst, name, Ddeml.CP_WINANSI); hDDEData = Ddeml.DdeClientTransaction(null, 0, hconvCurrent, hszItem, ConversionFormat.TEXT, //CF_TEXT, (int)Ddeml.XTYP_REQUEST, 5000, // ms timeout ref dwResult); Ddeml.DdeFreeStringHandle(dwDDEInst, hszItem); if (hDDEData != IntPtr.Zero) { sbyte *pData = (sbyte *)Ddeml.DdeAccessData(hDDEData, ref dwLength); { if ((pData != null) && (dwLength != 0)) { return(new string(pData, 0, dwLength)); } } } } return(null); }
public int Execute(string command) { int res = 0; byte[] data = Encoding.ASCII.GetBytes(command); Ddeml.DdeClientTransaction(data, data.Length, hconvCurrent, IntPtr.Zero, ConversionFormat.NONE, Ddeml.XTYP_EXECUTE, _timeOut, ref res); return(res); }
//与Server建立Hoot连接 public unsafe bool TransactItem(string name) { IntPtr hszItem, hDDEData; int dwResult = 0; if (string.IsNullOrEmpty(name)) { return(false); } if (hconvCurrent != IntPtr.Zero) { hszItem = Ddeml.DdeCreateStringHandle(dwDDEInst, name, Ddeml.CP_WINANSI); hDDEData = Ddeml.DdeClientTransaction(null, 0, hconvCurrent, hszItem, ConversionFormat.TEXT, //CF_TEXT, Ddeml.XTYP_ADVSTART, Ddeml.TIMEOUT_ASYNC, // ms timeout ref dwResult); Ddeml.DdeFreeStringHandle(dwDDEInst, hszItem); if (hDDEData != IntPtr.Zero) { try { int dwLength = 0; sbyte *pData = (sbyte *)Ddeml.DdeAccessData(hDDEData, ref dwLength); if ((pData != null) && (dwLength != 0)) { if (DDEValueChange != null) { DDEValueChange(this, new DDEValueChangeEventArgs(name, new string(pData, 0, dwLength))); } } } catch { } finally { Ddeml.DdeUnaccessData(hDDEData); } return(true); } else { return(false); } } else { return(false); } }
//必须设置item.ItemName和item.ItemValue后调用 public int Poke(string name, string value) { IntPtr hszItem, hDDEData; int dwResult = 0; if (string.IsNullOrEmpty(name)) { return(-2); } if (hconvCurrent != IntPtr.Zero) { hszItem = Ddeml.DdeCreateStringHandle(dwDDEInst, name, Ddeml.CP_WINANSI); if (!string.IsNullOrEmpty(name)) { //int errcode=Win32.DdeGetLastError(dwDDEInst); byte[] ByteArray = Encoding.ASCII.GetBytes(value); IntPtr hd = Ddeml.DdeCreateDataHandle(dwDDEInst, ByteArray, ByteArray.Length, 0, hszItem, ConversionFormat.TEXT, 0); hDDEData = Ddeml.DdeClientTransaction( ByteArray, ByteArray.Length, hconvCurrent, hszItem, ConversionFormat.TEXT, //CF_TEXT, Ddeml.XTYP_POKE, Ddeml.TIMEOUT_ASYNC, // ms timeout ref dwResult); Ddeml.DdeFreeStringHandle(dwDDEInst, hszItem); if (hDDEData != IntPtr.Zero) { return(1); } } return(-1); } else { return(-1); } }
// Arrête une transaction Advise. public void AdvStop(IntPtr hConv, string item, ConversionFormat wFormat) { if (!IsRegistered) { return; } // Création de la chaîne DDE de l'élément. IntPtr hszItem = Ddeml.DdeCreateStringHandle(_InstanceId, item, Ddeml.CP_WINANSI); if ((hszItem == IntPtr.Zero) && (item.Length != 0)) { return; } // Exécution de la transaction. int res = 0; Ddeml.DdeClientTransaction(null, 0, hConv, hszItem, wFormat, Ddeml.XTYP_ADVSTOP, Ddeml.TIMEOUT_ASYNC, ref res); // Libération de la chaîne DDE. if (hszItem != IntPtr.Zero) { Ddeml.DdeFreeStringHandle(_InstanceId, hszItem); } }
// Démarre une transaction Advise. public bool AdvStart(IntPtr hConv, string item, ConversionFormat wFormat, int wFlag) { if (!IsRegistered) { return(false); } int res = 0; // Création de la chaîne DDE de l'élément. IntPtr hszItem = Ddeml.DdeCreateStringHandle(_InstanceId, item, Ddeml.CP_WINANSI); if ((hszItem == IntPtr.Zero) && (item.Length != 0)) { return(false); } // Exécution de la transaction. Ddeml.DdeClientTransaction(null, 0, hConv, hszItem, wFormat, (wFlag == Ddeml.XTYPF_ACKREQ) ? (Ddeml.XTYP_ADVSTARTACKREQ) : ((wFlag == Ddeml.XTYPF_NODATA) ? (Ddeml.XTYP_ADVSTARTNODATA) : (Ddeml.XTYP_ADVSTART)), Ddeml.TIMEOUT_ASYNC, ref res); // Libération de la chaîne DDE. if (hszItem != IntPtr.Zero) { Ddeml.DdeFreeStringHandle(_InstanceId, hszItem); } return(res != 0); }