C#做的DDE客户端

实在感觉不好意思,因为工作忙,长时间没写什么东西了,这是我用C#
写的DDE客户端,因为.net不支持DDE,就用API函数实现,大家看看有用吗

下面是 一些API声明

None.gif using  System;
None.gif
using  System.Drawing;
None.gif
using  System.Text;
None.gif
using  System.Runtime.InteropServices;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ //
None.gif //  namspace to wrap Win32 API functions.
None.gif
//
ExpandedBlockStart.gifContractedBlock.gif
namespace  Win32API  dot.gif {
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif    
Win32 API 结构声明例子#region Win32 API 结构声明例子
InBlock.gif    [StructLayout(LayoutKind.Sequential)]
InBlock.gif    
public struct POINT 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public POINT(int xx, int yy) dot.gif{ x=xx; y=yy; }
InBlock.gif        
public int x;
InBlock.gif        
public int y;
InBlock.gif        
public override string ToString() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            String s 
= String.Format("({0},{1})", x, y);
InBlock.gif            
return s;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [StructLayout(LayoutKind.Sequential)]
InBlock.gif    
public struct SIZE 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public SIZE(int cxx, int cyy) dot.gif{ cx=cxx; cy=cyy; }
InBlock.gif        
public int cx;
InBlock.gif        
public int cy;
InBlock.gif        
public override string ToString() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            String s 
= String.Format("({0},{1})", cx, cy);
InBlock.gif            
return s;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [StructLayout(LayoutKind.Sequential)]
InBlock.gif    
public struct RECT 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public int left;
InBlock.gif        
public int top;
InBlock.gif        
public int right;
InBlock.gif        
public int bottom;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public int Width()        dot.gifreturn right - left; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public int Height()        dot.gifreturn bottom - top; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public POINT TopLeft()    dot.gifreturn new POINT(left,top); }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public SIZE  Size()        dot.gifreturn new SIZE(Width(), Height()); }
InBlock.gif        
public override string ToString() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            String s 
= String.Format("{0}x{1}", TopLeft(), Size());
InBlock.gif            
return s;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif    
DDE所需的结构声明#region DDE所需的结构声明
InBlock.gif
InBlock.gif    [StructLayout(LayoutKind.Sequential)]
InBlock.gif    
public struct SECURITY_QUALITY_OF_SERVICE
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif// sqos  
InBlock.gif
        public ushort Length; 
InBlock.gif        
public int ImpersonationLevel; //SECURITY_IMPERSONATION_LEVEL 
InBlock.gif
        public int ContextTrackingMode; //SECURITY_CONTEXT_TRACKING_MODE 
InBlock.gif
        public bool EffectiveOnly; 
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    [StructLayout(LayoutKind.Sequential)]
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public struct CONVCONTEXTdot.gif{
InBlock.gif        
public uint  cb; 
InBlock.gif        
public uint  wFlags; 
InBlock.gif        
public uint  wCountryID; 
InBlock.gif        
public int   iCodePage; 
InBlock.gif        
public ushort dwLangID; 
InBlock.gif        
public ushort dwSecurity; 
InBlock.gif        
public SECURITY_QUALITY_OF_SERVICE qos;  // client side's quality of service 
ExpandedSubBlockEnd.gif
    }
 
InBlock.gif
InBlock.gif    [StructLayout(LayoutKind.Sequential)]
InBlock.gif    
public struct CONVINFO
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{  // ci  
InBlock.gif
        public ushort        cb; 
InBlock.gif        
public ushort       hUser; 
InBlock.gif        
public int       hConvPartner; 
InBlock.gif        
public int          hszSvcPartner; 
InBlock.gif        
public int         hszServiceReq; 
InBlock.gif        
public int         hszTopic; 
InBlock.gif        
public int         hszItem; 
InBlock.gif        
public uint        wFmt; 
InBlock.gif        
public uint        wType; 
InBlock.gif        
public uint        wStatus; 
InBlock.gif        
public uint        wConvst; 
InBlock.gif        
public uint        wLastError; 
InBlock.gif        
public int   hConvList; 
InBlock.gif        
public CONVCONTEXT ConvCtxt; 
InBlock.gif        
public int        hwnd; 
InBlock.gif        
public int        hwndPartner; 
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//DDE回调代理
InBlock.gif
    public delegate int DdeCallback(
InBlock.gif    
uint uType,    // transaction type
InBlock.gif
    uint uFmt,    // clipboard data format
InBlock.gif
    int hconv,    // handle to the conversation
InBlock.gif
    int hsz1,    // handle to a string
InBlock.gif
    int hsz2,    // handle to a string
InBlock.gif
    int hdata,    // handle to a global memory object
InBlock.gif
    uint dwData1,    // transaction-specific data
InBlock.gif
    uint dwData2     // transaction-specific data
InBlock.gif
    );
ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif    
public class Win32 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
DDE Win32 API 函数声明例子#region DDE Win32 API 函数声明例子
InBlock.gif        [DllImport(
"user32.dll")]
InBlock.gif        
public static extern bool IsWindowVisible(int hwnd);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll")]
InBlock.gif        
public static extern int GetWindowText(int hwnd,
InBlock.gif            StringBuilder buf, 
int nMaxCount);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll")]
InBlock.gif        
public static extern int GetClassName(int hwnd,
InBlock.gif            [MarshalAs(UnmanagedType.LPStr)] StringBuilder buf,
InBlock.gif            
int nMaxCount);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll")]
InBlock.gif        
public static extern int GetWindowRect(int hwnd, ref RECT rc);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll")]
InBlock.gif        
// note the runtime knows how to marshal a Rectangle
InBlock.gif
        public static extern int GetWindowRect(int hwnd, ref Rectangle rc);
InBlock.gif        
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="MessageBox")]  
InBlock.gif        
public static extern int MessageBox(int hWnd, String text, String caption, uint type);  
ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
DDE Win32 API 函数声明#region DDE Win32 API 函数声明
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// C#工程中使用DDE/NETDDE的API函数声明集合
InBlock.gif        
/// //需要使用DDE回调代理和一些结构
InBlock.gif        
///    //            public delegate int DdeCallback(
InBlock.gif        
///    //            uint uType,    // transaction type
InBlock.gif        
///    //            uint uFmt,    // clipboard data format
InBlock.gif        
///    //            int hconv,    // handle to the conversation
InBlock.gif        
///    //            int hsz1,    // handle to a string
InBlock.gif        
///    //            int hsz2,    // handle to a string
InBlock.gif        
///    //            int hdata,    // handle to a global memory object
InBlock.gif        
///    //            uint dwData1,    // transaction-specific data
InBlock.gif        
///    //            uint dwData2     // transaction-specific data
InBlock.gif        
///    //            );
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeInitialize")]  
InBlock.gif        
public static extern int DdeInitialize(ref int pidInst, DdeCallback pfnCallback,int afCmd,int ulRes);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeCreateStringHandle")]  
InBlock.gif        
public static extern int DdeCreateStringHandle(int idInst,string psz,int iCodePage);
InBlock.gif        
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeConnect")]  
InBlock.gif        
public unsafe static extern int DdeConnect(int idInst,int hszService,int hszTopic, ref CONVCONTEXT pCC);
InBlock.gif        
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeFreeStringHandle")]  
InBlock.gif        
public static extern int DdeFreeStringHandle(int idInst,int hsz);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeClientTransaction")]  
InBlock.gif        
public static extern int DdeClientTransaction(Byte[] pData,int ByVal,int hConv,int hszItem,
InBlock.gif                                                    
int wFmt,int wType,uint dwTimeout,ref int pdwResult);
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeAccessData")]  
InBlock.gif        
public static extern int DdeAccessData(int hData,ref int pcbDataSize);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeUnaccessData")]  
InBlock.gif        
public static extern int DdeUnaccessData(int hData);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeDisconnect")]  
InBlock.gif        
public static extern int DdeDisconnect(int hConv);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeGetLastError")]  
InBlock.gif        
public static extern int DdeGetLastError(int idInst);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeAbandonTransaction")]
InBlock.gif        
public static extern int DdeAbandonTransaction(int idInst,int hConv,int idTransaction);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeAddData")]
InBlock.gif        
public static extern int DdeAddData(int hData,byte pSrc,int cb,int cbOff);
InBlock.gif 
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeCmpStringHandles")]
InBlock.gif        
public static extern int DdeCmpStringHandles(int hsz1,int hsz2);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeConnectList")]
InBlock.gif        
public static extern int DdeConnectList(int idInst,int hszService,int hszTopic,int hConvList,ref CONVCONTEXT pCC);
InBlock.gif        
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeCreateDataHandle")]
InBlock.gif        
public static extern int DdeCreateDataHandle(int idInst,byte[] pSrc,int cb,int cbOff,
InBlock.gif                                                
int hszItem,int wFmt,int afCmd);
InBlock.gif        
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeDisconnectList")]
InBlock.gif        
public static extern int DdeDisconnectList(int hConvList);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeEnableCallback")]
InBlock.gif        
public static extern int DdeEnableCallback(int idInst,int hConv,int wCmd);
InBlock.gif        
InBlock.gif        
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeFreeDataHandle")]
InBlock.gif        
public static extern int DdeFreeDataHandle(int hData);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeGetData")]
InBlock.gif        
public static extern int DdeGetData(int hData,byte pDst,int cbMax,int cbOff);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeImpersonateClient")]
InBlock.gif        
public static extern int DdeImpersonateClient(int hConv);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeKeepStringHandle")]
InBlock.gif        
public static extern int DdeKeepStringHandle(int idInst,int hsz);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeNameService")]
InBlock.gif        
public static extern int DdeNameService(int idInst,int hsz1,int hsz2,int afCmd);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdePostAdvise")]
InBlock.gif        
public static extern int DdePostAdvise(int idInst,int hszTopic,int hszItem);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeQueryConvInfo")]
InBlock.gif        
public static extern int DdeQueryConvInfo(int hConv,int idTransaction,ref CONVINFO pConvInfo);
InBlock.gif        
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeQueryNextServer")]
InBlock.gif        
public static extern int DdeQueryNextServer(int hConvList,int hConvPrev);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeQueryString")]
InBlock.gif        
public unsafe static extern int DdeQueryString(int idInst,int hsz,sbyte* psz,int cchMax,int iCodePage);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeReconnect")]
InBlock.gif        
public static extern int DdeReconnect(int hConv);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeSetQualityOfService")]
InBlock.gif        
public static extern int DdeSetQualityOfService(int hWndClient, ref SECURITY_QUALITY_OF_SERVICE pqosNew,ref SECURITY_QUALITY_OF_SERVICE pqosPrev);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeSetUserHandle")]
InBlock.gif        
public static extern int DdeSetUserHandle(int hConv,int id,int hUser);
InBlock.gif
InBlock.gif        [DllImport(
"user32.dll", EntryPoint="DdeUninitialize")]
InBlock.gif        
public static extern int DdeUninitialize(int idInst);
InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion
 
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

下面是客户端类:

 

None.gif using  System;
None.gif
using  Win32API;
None.gif
using  System.Runtime.InteropServices;
None.gif
using  System.Windows.Forms.Design;
None.gif
using  System.Collections;
None.gif
using  System.Timers;
None.gif
using  System.Text;
None.gif
using  System.Threading ;
None.gif
namespace  MWDataLog
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// DdeClient 定义单个Service的单个Topic了连接
InBlock.gif    
/// 支持NetDDE,连接方式为:
InBlock.gif    
/// Service为“\\SERVERNODENAME\APPLICATIONNAME”
InBlock.gif    
/// Topic为“TOPICNAME”
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class DdeItem
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public int ItemID;
InBlock.gif        
public DdeClient Dc;
InBlock.gif        
public string ItemName;
InBlock.gif        
public string ItemDescription;
InBlock.gif        
public string ItemValue;
InBlock.gif        
public DdeItem(DdeClient iDc,int itemID,string  iName,string Desc)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ItemName 
= iName;
InBlock.gif            ItemDescription
=Desc;
InBlock.gif            Dc 
= iDc;
InBlock.gif            ItemID
=itemID;
InBlock.gif            ItemValue 
= "";
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
public class DdeClient
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
DDE用常量定义#region DDE用常量定义
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// ///
ExpandedSubBlockEnd.gif        
/// /***** conversation states (usState) *****/

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint XST_NULL          =    0;  /**//* quiescent states */
InBlock.gif        
public const uint XST_INCOMPLETE    =    1;
InBlock.gif        
public const uint XST_CONNECTED     =    2;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint XST_INIT1         =    3/**//* mid-initiation states */
InBlock.gif        
public const uint XST_INIT2         =    4;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint XST_REQSENT       =    5;  /**//* active conversation states */
InBlock.gif        
public const uint XST_DATARCVD       =   6;
InBlock.gif        
public const uint XST_POKESENT      =    7;
InBlock.gif        
public const uint XST_POKEACKRCVD    =   8;
InBlock.gif        
public const uint XST_EXECSENT       =   9;
InBlock.gif        
public const uint XST_EXECACKRCVD   =   10;
InBlock.gif        
public const uint XST_ADVSENT       =   11;
InBlock.gif        
public const uint XST_UNADVSENT     =   12;
InBlock.gif        
public const uint XST_ADVACKRCVD    =   13;
InBlock.gif        
public const uint XST_UNADVACKRCVD  =   14;
InBlock.gif        
public const uint XST_ADVDATASENT   =   15;
InBlock.gif        
public const uint XST_ADVDATAACKRCVD =  16;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//* used in LOWORD(dwData1) of XTYP_ADVREQ callbacksdot.gif */
InBlock.gif        
public const uint CADV_LATEACK     =    0xFFFF;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//***** conversation status bits (fsStatus) *****/
InBlock.gif
InBlock.gif        
public const uint ST_CONNECTED      =      0x0001;
InBlock.gif        
public const uint ST_ADVISE        =       0x0002;
InBlock.gif        
public const uint ST_ISLOCAL       =       0x0004;
InBlock.gif        
public const uint ST_BLOCKED       =       0x0008;
InBlock.gif        
public const uint ST_CLIENT        =       0x0010;
InBlock.gif        
public const uint ST_TERMINATED    =       0x0020;
InBlock.gif        
public const uint ST_INLIST       =        0x0040;
InBlock.gif        
public const uint ST_BLOCKNEXT    =        0x0080;
InBlock.gif        
public const uint ST_ISSELF       =        0x0100;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//* DDE constants for wStatus field */
InBlock.gif
InBlock.gif        
public const uint  DDE_FACK        =        0x8000;
InBlock.gif        
public const uint  DDE_FBUSY        =       0x4000;
InBlock.gif        
public const uint  DDE_FDEFERUPD    =       0x4000;
InBlock.gif        
public const uint  DDE_FACKREQ      =       0x8000;
InBlock.gif        
public const uint  DDE_FRELEASE     =       0x2000;
InBlock.gif        
public const uint  DDE_FREQUESTED    =      0x1000;
InBlock.gif        
public const uint  DDE_FAPPSTATUS   =       0x00ff;
InBlock.gif        
public const uint  DDE_FNOTPROCESSED =      0x0000;
InBlock.gif
InBlock.gif        
public const uint  DDE_FACKRESERVED   =     (~(DDE_FACK | DDE_FBUSY | DDE_FAPPSTATUS));
InBlock.gif        
public const uint  DDE_FADVRESERVED   =     (~(DDE_FACKREQ | DDE_FDEFERUPD));
InBlock.gif        
public const uint  DDE_FDATRESERVED    =    (~(DDE_FACKREQ | DDE_FRELEASE | DDE_FREQUESTED));
InBlock.gif        
public const uint  DDE_FPOKRESERVED   =     (~(DDE_FRELEASE));
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//***** message filter hook types *****/
InBlock.gif
InBlock.gif        
public const uint MSGF_DDEMGR     =        0x8001;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//***** codepage constants ****/
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint  CP_WINANSI  =    1004;   /**//* default codepage for windows & old DDE convs. */
InBlock.gif        
public const uint  CP_WINUNICODE =  1200;
InBlock.gif        
InBlock.gif        
//#ifdef UNICODE
InBlock.gif        
//public const uint  CP_WINNEUTRAL  = CP_WINUNICODE
InBlock.gif        
//#else  // !UNICODE
InBlock.gif        
//public const uint  CP_WINNEUTRAL   CP_WINANSI
InBlock.gif        
//#endif // !UNICODE
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//***** transaction types *****/
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint XTYPF_NOBLOCK      =      0x0002;  /**//* CBR_BLOCK will not work */
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint XTYPF_NODATA       =      0x0004;  /**//* DDE_FDEFERUPD */
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint XTYPF_ACKREQ       =      0x0008;  /**//* DDE_FACKREQ */
InBlock.gif
InBlock.gif        
public const uint XCLASS_MASK       =       0xFC00;
InBlock.gif        
public const uint XCLASS_BOOL       =       0x1000;
InBlock.gif        
public const uint XCLASS_DATA       =       0x2000;
InBlock.gif        
public const uint XCLASS_FLAGS      =       0x4000;
InBlock.gif        
public const uint XCLASS_NOTIFICATION  =    0x8000;
InBlock.gif
InBlock.gif        
public const uint XTYP_ERROR        =      (0x0000 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK );
InBlock.gif        
public const uint XTYP_ADVDATA      =      (0x0010 | XCLASS_FLAGS         );
InBlock.gif        
public const uint XTYP_ADVREQ       =      (0x0020 | XCLASS_DATA | XTYPF_NOBLOCK );
InBlock.gif        
public const uint XTYP_ADVSTART     =      (0x0030 | XCLASS_BOOL          );
InBlock.gif        
public const uint XTYP_ADVSTOP      =      (0x0040 | XCLASS_NOTIFICATION);
InBlock.gif        
public const uint XTYP_EXECUTE      =      (0x0050 | XCLASS_FLAGS         );
InBlock.gif        
public const uint XTYP_CONNECT      =      (0x0060 | XCLASS_BOOL | XTYPF_NOBLOCK);
InBlock.gif        
public const uint XTYP_CONNECT_CONFIRM  =  (0x0070 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK);
InBlock.gif        
public const uint XTYP_XACT_COMPLETE   =   (0x0080 | XCLASS_NOTIFICATION  );
InBlock.gif        
public const uint XTYP_POKE        =       (0x0090 | XCLASS_FLAGS         );
InBlock.gif        
public const uint XTYP_REGISTER     =      (0x00A0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK);
InBlock.gif        
public const uint XTYP_REQUEST       =     (0x00B0 | XCLASS_DATA          );
InBlock.gif        
public const uint XTYP_DISCONNECT    =     (0x00C0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK);
InBlock.gif        
public const uint XTYP_UNREGISTER    =     (0x00D0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK);
InBlock.gif        
public const uint XTYP_WILDCONNECT   =     (0x00E0 | XCLASS_DATA | XTYPF_NOBLOCK);
InBlock.gif
InBlock.gif        
public const uint XTYP_MASK       =         0x00F0;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint XTYP_SHIFT      =         4 ; /**//* shift to turn XTYP_ uinto an index */
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//***** Timeout constants *****/
InBlock.gif
InBlock.gif        
public const uint TIMEOUT_ASYNC     =      0xFFFFFFFF;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//***** Transaction ID constants *****/
InBlock.gif
InBlock.gif        
public const uint QID_SYNC         =       0x7FFFFFFF;
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public const uint DMLERR_NO_ERROR           =         0;       /**//* must be 0 */
InBlock.gif
InBlock.gif        
public const uint DMLERR_FIRST               =        0x4000;
InBlock.gif
InBlock.gif        
public const uint DMLERR_ADVACKTIMEOUT        =       0x4000;
InBlock.gif        
public const uint DMLERR_BUSY                 =       0x4001;
InBlock.gif        
public const uint DMLERR_DATAACKTIMEOUT        =      0x4002;
InBlock.gif        
public const uint DMLERR_DLL_NOT_INITIALIZED   =      0x4003;
InBlock.gif        
public const uint DMLERR_DLL_USAGE             =      0x4004;
InBlock.gif        
public const uint DMLERR_EXECACKTIMEOUT        =      0x4005;
InBlock.gif        
public const uint DMLERR_INVALIDPARAMETER      =      0x4006;
InBlock.gif        
public const uint DMLERR_LOW_MEMORY            =      0x4007;
InBlock.gif        
public const uint DMLERR_MEMORY_ERROR          =      0x4008;
InBlock.gif        
public const uint DMLERR_NOTPROCESSED          =      0x4009;
InBlock.gif        
public const uint DMLERR_NO_CONV_ESTABLISHED   =      0x400a;
InBlock.gif        
public const uint DMLERR_POKEACKTIMEOUT        =      0x400b;
InBlock.gif        
public const uint DMLERR_POSTMSG_FAILED        =      0x400c;
InBlock.gif        
public const uint DMLERR_REENTRANCY            =      0x400d;
InBlock.gif        
public const uint DMLERR_SERVER_DIED           =      0x400e;
InBlock.gif        
public const uint DMLERR_SYS_ERROR             =      0x400f;
InBlock.gif        
public const uint DMLERR_UNADVACKTIMEOUT      =       0x4010;
InBlock.gif        
public const uint DMLERR_UNFOUND_QUEUE_ID      =      0x4011;
InBlock.gif
InBlock.gif        
public const uint DMLERR_LAST                  =      0x4011;
InBlock.gif
InBlock.gif        
public const uint EC_ENABLEALL     =       0;
InBlock.gif        
public const uint EC_ENABLEONE     =       ST_BLOCKNEXT;
InBlock.gif        
public const uint EC_DISABLE       =       ST_BLOCKED;
InBlock.gif        
public const uint EC_QUERYWAITING  =       2;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// </summary>
ExpandedSubBlockEnd.gif        #endregion

InBlock.gif        
private int dwDDEInst;    // DDE Instance value
InBlock.gif
        private int hconvCurrent;
InBlock.gif        
private string lpszService;
InBlock.gif        
private string lpszTopic;
InBlock.gif        
private ArrayList alDdeItemList;
InBlock.gif        
private Win32API.DdeCallback myCallback;
InBlock.gif        
private System.Timers.Timer theTimer;//检查连接的计时器
InBlock.gif

InBlock.gif        
private bool bConnected;
InBlock.gif        
private bool bAutoConnect;
InBlock.gif        
public string LinkName;
InBlock.gif        
public string LinkDesc;
InBlock.gif
InBlock.gif        
public string Service
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return lpszService;    }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
setdot.gif{lpszService=value;    }
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public string Topic
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return lpszTopic;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
setdot.gif{lpszTopic=value;}    
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public ArrayList ItemList
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return alDdeItemList;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
setdot.gif{alDdeItemList=value;}    
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public bool Connected
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return bConnected;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
setdot.gif{bConnected=value;}    
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public bool AutoConnect
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return bAutoConnect;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
setdot.gif{bAutoConnect=value;}    
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public DdeClient(string theService,string theTopic,string Desc)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            dwDDEInst
=0;
InBlock.gif            hconvCurrent 
= 0;
InBlock.gif            lpszService
=theService;
InBlock.gif            lpszTopic
=theTopic;
InBlock.gif            alDdeItemList
=new ArrayList();
InBlock.gif            myCallback 
= new Win32API.DdeCallback(DdeClientCallback);
InBlock.gif
InBlock.gif            bConnected
=false;
InBlock.gif            LinkName 
= theService+"|"+theTopic;
InBlock.gif            LinkDesc 
= Desc;
InBlock.gif
InBlock.gif            theTimer 
= new System.Timers.Timer(2000);
InBlock.gif            theTimer.Elapsed
+=new ElapsedEventHandler(OnTimedEvent);
InBlock.gif            theTimer.AutoReset 
= true;
InBlock.gif            theTimer.Enabled 
= false;//暂时不用---设为false
ExpandedSubBlockEnd.gif
        }

InBlock.gif
InBlock.gif        
public override string ToString()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return Service+"|"+Topic;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public bool Initialize()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int iInitResult=0;
InBlock.gif            iInitResult 
= Win32.DdeInitialize(ref dwDDEInst, myCallback,
InBlock.gif                (
int)0x3f000,0);//CBF_FAIL_ALLSVRXACTIONS=0x3f000
InBlock.gif
            if(iInitResult==0)return true;
InBlock.gif            
else return false;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
//
InBlock.gif        
//
InBlock.gif
        private unsafe int DdeClientCallback(
InBlock.gif            
uint uType,    // transaction type
InBlock.gif
            uint uFmt,    // clipboard data format
InBlock.gif
            int hconv,    // handle to the conversation
InBlock.gif
            int hsz1,    // handle to a string
InBlock.gif
            int hsz2,    // handle to a string
InBlock.gif
            int hdata,    // handle to a global memory object
InBlock.gif
            uint dwData1,    // transaction-specific data
InBlock.gif
            uint dwData2)     // transaction-specific data
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif{
InBlock.gif            
int dwLength=0;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
switch (uType) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
case 0x4010://XTYP_ADVDATA:
InBlock.gif
                        try
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
sbyte* pData = (sbyte *)Win32.DdeAccessData(hdata, ref dwLength);
InBlock.gif                            
if((pData!=null&& (dwLength != 0))
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                
sbyte* pSZ=stackalloc sbyte[30];
InBlock.gif                                Win32.DdeQueryString(dwDDEInst,hsz2,pSZ,
28,(int)CP_WINANSI);
InBlock.gif                                
if(ItemList.Count>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif                                    
for(int i=0;i<ItemList.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif                                        
string tmpSZ=new string(pSZ);
InBlock.gif                                        
if(((DdeItem)ItemList[i]).ItemName.ToUpper()==tmpSZ.ToUpper())
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif                                            
string tmpData = new string(pData,0,dwLength);
InBlock.gif                                            ((DdeItem)ItemList[i]).ItemValue
=tmpData;
ExpandedSubBlockEnd.gif                                        }

ExpandedSubBlockEnd.gif                                    }

ExpandedSubBlockEnd.gif                                }

ExpandedSubBlockEnd.gif                            }

ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockStart.gifContractedSubBlock.gif                        
catchdot.gif{}
InBlock.gif                        
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
if(hdata!=0)Win32.DdeUnaccessData(hdata);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
break;
InBlock.gif                    
case 0x80C2://XTYP_DISCONNECT:
InBlock.gif
                        Connected = false;
InBlock.gif                        
break;
InBlock.gif                    
default:
InBlock.gif                        
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//
ExpandedSubBlockEnd.gif
            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return (int)DDE_FACK;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//当前没起作用
InBlock.gif
        private void OnTimedEvent(object source, ElapsedEventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            theTimer.Enabled 
= false;
InBlock.gif            
if(!Connected)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(AutoConnect)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    ReEstablishLink();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            theTimer.Enabled 
= true;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//*
InBlock.gif        //当前的Server是否可用(待测试)
InBlock.gif        private bool IsServiceAvailable(string lpszService)
InBlock.gif        {
InBlock.gif            int hszService;
InBlock.gif            int hConv;
InBlock.gif
InBlock.gif            hszService = Win32.DdeCreateStringHandle(dwDDEInst,lpszService,(int)CP_WINANSI);
InBlock.gif            //
InBlock.gif            // Try to connect to any topic
InBlock.gif            //
InBlock.gif            Win32API.CONVCONTEXT cc=new CONVCONTEXT();
InBlock.gif            hConv = Win32.DdeConnect(dwDDEInst,hszService,0,ref cc);
InBlock.gif
InBlock.gif            // Free the HSZs now
InBlock.gif            Win32.DdeFreeStringHandle(dwDDEInst, hszService);
InBlock.gif
InBlock.gif            if(hConv!=0) 
InBlock.gif            {
InBlock.gif                Win32.DdeDisconnect(hConv);
InBlock.gif                return true;
InBlock.gif            }
InBlock.gif            return false;
InBlock.gif        }
ExpandedSubBlockEnd.gif        
*/

InBlock.gif        
//  [10/24/2003]
InBlock.gif        
//建立连接
InBlock.gif
        public unsafe bool EstablishLink()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int hConv=0;
InBlock.gif            
int  hszService, hszTopic;
InBlock.gif            
InBlock.gif            Demolish();
//如果是第一次,则什么也不做
InBlock.gif

InBlock.gif            Initialize();
InBlock.gif
InBlock.gif            
// Connect to the server
InBlock.gif
            hszTopic = Win32.DdeCreateStringHandle(dwDDEInst,lpszTopic,(int)CP_WINANSI);
InBlock.gif            hszService 
= Win32.DdeCreateStringHandle(dwDDEInst,lpszService,(int)CP_WINANSI);
InBlock.gif            Win32API.CONVCONTEXT cc
=new CONVCONTEXT();
InBlock.gif            cc.cb
=(uint)sizeof(Win32API.CONVCONTEXT);
InBlock.gif            hConv 
= Win32.DdeConnect(dwDDEInst,hszService,hszTopic,ref cc);
InBlock.gif            
int DdeErrcode=Win32.DdeGetLastError(dwDDEInst);
InBlock.gif
InBlock.gif            Win32.DdeFreeStringHandle(dwDDEInst, hszTopic);
InBlock.gif            Win32.DdeFreeStringHandle(dwDDEInst, hszService);
InBlock.gif
InBlock.gif            
if (hConv!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(hconvCurrent!=0
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Win32.DdeDisconnect(hconvCurrent);
ExpandedSubBlockEnd.gif                }

InBlock.gif                hconvCurrent 
= hConv;
InBlock.gif                Connected 
= true;
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Connected 
= false;
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
//销毁连接
InBlock.gif
        public unsafe void Demolish()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(dwDDEInst!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Win32.DdeUninitialize(dwDDEInst);
InBlock.gif                dwDDEInst
=0;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(hconvCurrent!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Win32.DdeDisconnect(hconvCurrent);
InBlock.gif                hconvCurrent
=0;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//建立连接
InBlock.gif
        public unsafe bool ReEstablishLink()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
bool Elr=EstablishLink();
InBlock.gif
InBlock.gif            
if (Elr)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Connected 
= true;
InBlock.gif                
foreach(DdeItem item in ItemList)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    TransactItem(item);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Connected 
= false;
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }
            
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
//  [10/24/2003]
InBlock.gif        
//与Server建立Hoot连接
InBlock.gif
        public unsafe bool TransactItem(DdeItem item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int  hszItem=0;
InBlock.gif            
int dwResult=0;
InBlock.gif            
int hDDEData=0;
InBlock.gif            
if(item==null)return false;
InBlock.gif            
if((hconvCurrent!=0&& item.ItemName !="")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                hszItem 
= Win32.DdeCreateStringHandle(dwDDEInst,item.ItemName,(int)CP_WINANSI);
InBlock.gif
InBlock.gif                hDDEData 
= Win32.DdeClientTransaction(null,
InBlock.gif                    
0,
InBlock.gif                    hconvCurrent,
InBlock.gif                    hszItem,
InBlock.gif                    
1,//CF_TEXT,
InBlock.gif
                    (int)XTYP_ADVSTART,
InBlock.gif                    TIMEOUT_ASYNC, 
// ms timeout
InBlock.gif
                    ref dwResult);
InBlock.gif
InBlock.gif                Win32.DdeFreeStringHandle(dwDDEInst, hszItem);
InBlock.gif
InBlock.gif                
if(hDDEData!=0
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
int dwLength=0;
InBlock.gif                        
sbyte* pData = (sbyte *)Win32.DdeAccessData(hDDEData, ref dwLength);
InBlock.gif                        
if((pData!=null&& (dwLength != 0))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
string tmpData = new string(pData,0,dwLength);
InBlock.gif                            item.ItemValue
=tmpData;
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockStart.gifContractedSubBlock.gif                    
catchdot.gif{}
InBlock.gif                    
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        Win32.DdeUnaccessData(hDDEData);
ExpandedSubBlockEnd.gif                    }

InBlock.gif
InBlock.gif                    
return true;
ExpandedSubBlockEnd.gif                }
 
InBlock.gif                
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
else 
InBlock.gif                
return false;        
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//必须设置item.ItemName和item.ItemValue后调用
InBlock.gif
        public unsafe bool PokeItem(DdeItem item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int  hszItem=0;
InBlock.gif            
int dwResult=0;
InBlock.gif            
int hDDEData=0;
InBlock.gif            
if(item==null)return false;
InBlock.gif            
if((hconvCurrent!=0&& item.ItemName !="")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                hszItem 
= Win32.DdeCreateStringHandle(dwDDEInst,item.ItemName,(int)CP_WINANSI);
InBlock.gif                
InBlock.gif                
//int errcode=Win32.DdeGetLastError(dwDDEInst);
InBlock.gif

InBlock.gif                ASCIIEncoding AE 
= new ASCIIEncoding();
InBlock.gif                
byte[] ByteArray = AE.GetBytes(item.ItemValue);
InBlock.gif                
int hd = Win32.DdeCreateDataHandle(dwDDEInst,ByteArray,ByteArray.Length,0,hszItem,1,0);
InBlock.gif
InBlock.gif                hDDEData 
= Win32.DdeClientTransaction(
InBlock.gif                                                ByteArray,ByteArray.Length,
InBlock.gif                                                hconvCurrent,hszItem,
InBlock.gif                                                
1,//CF_TEXT,
InBlock.gif
                                                (int)XTYP_POKE ,
InBlock.gif                                                 
0xFFFFFFFF// ms timeout
InBlock.gif
                                                ref dwResult);
InBlock.gif                Win32.DdeFreeStringHandle(dwDDEInst, hszItem);
InBlock.gif
InBlock.gif                
if(hDDEData!=0
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return true;
ExpandedSubBlockEnd.gif                }
 
InBlock.gif                
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
else 
InBlock.gif                
return false;        
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void PollRequestItem()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
InBlock.gif            
if(ItemList.Count>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for(int i=0;i<ItemList.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    RequestItem((DdeItem)ItemList[i]);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//  [10/24/2003]
InBlock.gif        
//主动请求Item的值
InBlock.gif
        public unsafe string RequestItem(DdeItem item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int  hszItem=0;
InBlock.gif            
int dwResult=0;
InBlock.gif            
int hDDEData=0;
InBlock.gif            
int dwLength=0;
InBlock.gif            
if(item==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                item.ItemValue
="";
InBlock.gif                
return "";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if((hconvCurrent!=0&& item.ItemName !="")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                hszItem 
= Win32.DdeCreateStringHandle(dwDDEInst,item.ItemName,(int)CP_WINANSI);
InBlock.gif
InBlock.gif                hDDEData 
= Win32.DdeClientTransaction(null,
InBlock.gif                    
0,
InBlock.gif                    hconvCurrent,
InBlock.gif                    hszItem,
InBlock.gif                    
1,//CF_TEXT,
InBlock.gif
                    (int)XTYP_REQUEST,
InBlock.gif                    
5000// ms timeout
InBlock.gif
                    ref dwResult);
InBlock.gif                Win32.DdeFreeStringHandle(dwDDEInst, hszItem);
InBlock.gif
InBlock.gif                
if(hDDEData!=0
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
sbyte* pData = (sbyte *)Win32.DdeAccessData(hDDEData, ref dwLength);
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
if((pData!=null&& (dwLength != 0))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
string tmpData = new string(pData,0,dwLength);
InBlock.gif                            item.ItemValue
=tmpData;
InBlock.gif                            
return tmpData;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            item.ItemValue
="";
InBlock.gif                            
return "";
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }
 
InBlock.gif                
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    item.ItemValue
="";
InBlock.gif                    
return "";
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                item.ItemValue
="";
InBlock.gif                
return "";
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
//
InBlock.gif

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


 

 

转载于:https://www.cnblogs.com/RockyWang/archive/2006/08/10/473275.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值