home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 February / DPPCPRO0299.ISO / February / Delphi / Install / DATA.Z / DDEML.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-09  |  15.7 KB  |  492 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Runtime Library                          }
  5. {       Windows 32bit API Interface Unit                }
  6. {                                                       }
  7. {       Copyright (c) 1992,96 Borland International     }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit Ddeml;
  12.  
  13. interface
  14.  
  15. uses Windows;
  16.  
  17. type
  18.   HConvList = Longint;
  19.   HConv = Longint;
  20.   HSz = Longint;
  21.   HDDEData = Longint;
  22.  
  23. type
  24.   { the following structure is for use with xtyp_WildConnect processing. }
  25.   PHSZPair = ^THSZPair;
  26.   THSZPair = record
  27.     hszSvc: HSZ;
  28.     hszTopic: HSZ;
  29.   end;
  30.  
  31.   { The following structure is used by DdeConnect() and DdeConnectList()
  32.     and by xtyp_Connect and xtyp_WildConnect callbacks. }
  33.  
  34.   PConvContext = ^TConvContext;
  35.   TConvContext = record
  36.     cb: UINT;            { set to sizeof(ConvCOnTEXT) }
  37.     wFlags: UINT;        { none currently defined. }
  38.     wCountryID: UINT;    { country code for topic/item strings used. }
  39.     iCodePage: Integer;  { codepage used for topic/item strings. }
  40.     dwLangID: DWORD;     { language ID for topic/item strings. }
  41.     dwSecurity: DWORD;   { Private security code. }
  42.     qos: TSecurityQualityOfService;  { used to support client impersonation }
  43.   end;
  44.  
  45. { The following structure is used by DdeQueryConvInfo(): }
  46.  
  47.   PConvInfo = ^TConvInfo;
  48.   TConvInfo = record
  49.     cb: DWORD;            { sizeof(CONVINFO)  }
  50.     hUser: DWORD;         { user specified field  }
  51.     hConvPartner: HConv;    { hConv on other end or 0 if non-ddemgr partner  }
  52.     hszSvcPartner: HSz;     { app name of partner if obtainable  }
  53.     hszServiceReq: HSz;     { AppName requested for connection  }
  54.     hszTopic: HSz;          { Topic name for conversation  }
  55.     hszItem: HSz;           { transaction item name or NULL if quiescent  }
  56.     wFmt: UINT;             { transaction format or NULL if quiescent  }
  57.     wType: UINT;            { XTYP_ for current transaction  }
  58.     wStatus: UINT;          { ST_ constant for current conversation  }
  59.     wConvst: UINT;          { XST_ constant for current transaction  }
  60.     wLastError: UINT;       { last transaction error.  }
  61.     hConvList: HConvList;   { parent hConvList if this conversation is in a list }
  62.     ConvCtxt: TConvContext; { conversation context }
  63.     hwnd: HWND;             { window handle for this conversation }
  64.     hwndPartner: HWND;      { partner window handle for this conversation }
  65.   end;
  66.  
  67. const
  68.   { conversation states (usState) }
  69.  
  70.   XST_NULL = 0;                 { quiescent states }
  71.   XST_INCOMPLETE = 1;
  72.   XST_CONNECTED = 2;
  73.   XST_INIT1 = 3;                { mid-initiation states }
  74.   XST_INIT2 = 4;
  75.   XST_REQSENT = 5;              { active conversation states }
  76.   XST_DATARCVD = 6;
  77.   XST_POKESENT = 7;
  78.   XST_POKEACKRCVD = 8;
  79.   XST_EXECSENT = 9;
  80.   XST_EXECACKRCVD = 10;
  81.   XST_ADVSENT = 11;
  82.   XST_UNADVSENT = 12;
  83.   XST_ADVACKRCVD = 13;
  84.   XST_UNADVACKRCVD = 14;
  85.   XST_ADVDATASENT = 15;
  86.   XST_ADVDATAACKRCVD = 16;
  87.  
  88.   { used in LOWORD(dwData1) of XTYP_ADVREQ callbacks... }
  89.  
  90.   CADV_LATEACK = $FFFF;
  91.  
  92.   { conversation status bits (fsStatus) }
  93.  
  94.   ST_CONNECTED = $0001;
  95.   ST_ADVISE = $0002;
  96.   ST_ISLOCAL = $0004;
  97.   ST_BLOCKED = $0008;
  98.   ST_CLIENT = $0010;
  99.   ST_TERMINATED = $0020;
  100.   ST_INLIST = $0040;
  101.   ST_BLOCKNEXT = $0080;
  102.   ST_ISSELF = $0100;
  103.  
  104.   { DDE constants for wStatus field }
  105.  
  106.   DDE_FACK = $8000;
  107.   DDE_FBUSY = $4000;
  108.   DDE_FDEFERUPD = $4000;
  109.   DDE_FACKREQ = $8000;
  110.   DDE_FRELEASE = $2000;
  111.   DDE_FREQUESTED = $1000;
  112.   DDE_FAPPSTATUS = $00ff;
  113.   DDE_FNOTPROCESSED = $0000;
  114.  
  115.   DDE_FACKRESERVED = $3ff0;
  116.   DDE_FADVRESERVED = $3fff;
  117.   DDE_FDATRESERVED = $4fff;
  118.   DDE_FPOKRESERVED = $dfff;
  119.  
  120.   { message filter hook types }
  121.  
  122.   MSGF_DDEMGR = $8001;
  123.  
  124.   { default codepage for windows & old DDE convs. }
  125.  
  126.   CP_WINANSI = 1004;
  127.   CP_WINUNICOCDE = 1200;
  128.  
  129.   { transaction types }
  130.  
  131.   XTYPF_NOBLOCK = $0002; { CBR_BLOCK will not work }
  132.   XTYPF_NODATA = $0004;  { DDE_FDEFERUPD }
  133.   XTYPF_ACKREQ = $0008;  { DDE_FACKREQ }
  134.  
  135.   XCLASS_MASK = $FC00;
  136.   XCLASS_BOOL = $1000;
  137.   XCLASS_DATA = $2000;
  138.   XCLASS_FLAGS = $4000;
  139.   XCLASS_NOTIFICATION = $8000;
  140.  
  141.   XTYP_ERROR = $0000 or XCLASS_NOTIFICATION or XTYPF_NOBLOCK;
  142.   XTYP_ADVDATA = $0010 or XCLASS_FLAGS;
  143.   XTYP_ADVREQ = $0020 or XCLASS_DATA or XTYPF_NOBLOCK;
  144.   XTYP_ADVSTART = $0030 or XCLASS_BOOL;
  145.   XTYP_ADVSTOP = $0040 or XCLASS_NOTIFICATION;
  146.   XTYP_EXECUTE = $0050 or XCLASS_FLAGS;
  147.   XTYP_CONNECT = $0060 or XCLASS_BOOL or XTYPF_NOBLOCK;
  148.   XTYP_CONNECT_CONFIRM = $0070 or XCLASS_NOTIFICATION or XTYPF_NOBLOCK;
  149.   XTYP_XACT_COMPLETE = $0080 or XCLASS_NOTIFICATION;
  150.   XTYP_POKE = $0090 or XCLASS_FLAGS;
  151.   XTYP_REGISTER = $00A0 or XCLASS_NOTIFICATION or XTYPF_NOBLOCK;
  152.   XTYP_REQUEST = $00B0 or XCLASS_DATA;
  153.   XTYP_DISCONNECT = $00C0 or XCLASS_NOTIFICATION or XTYPF_NOBLOCK;
  154.   XTYP_UNREGISTER = $00D0 or XCLASS_NOTIFICATION or XTYPF_NOBLOCK;
  155.   XTYP_WILDCONNECT = $00E0 or XCLASS_DATA or XTYPF_NOBLOCK;
  156.  
  157.   XTYP_MASK = $00F0;
  158.   XTYP_SHIFT = 4;  { shift to turn xtyp_ into an index }
  159.  
  160.   { Timeout constants }
  161.  
  162.   TIMEOUT_ASYNC =           -1;
  163.  
  164.   { Transaction ID constatnts }
  165.   QID_SYNC =                -1;
  166.  
  167.   { public strings used in DDE }
  168.  
  169.   SZDDESYS_TOPIC = 'System';
  170.   SZDDESYS_ITEM_TOPICS = 'Topics';
  171.   SZDDESYS_ITEM_SYSITEMS = 'SysItems';
  172.   SZDDESYS_ITEM_RTNMSG = 'ReturnMessage';
  173.   SZDDESYS_ITEM_STATUS = 'Status';
  174.   SZDDESYS_ITEM_FORMATS = 'Formats';
  175.   SZDDESYS_ITEM_HELP = 'Help';
  176.   SZDDE_ITEM_ITEMLIST = 'TopicItemList';
  177.  
  178. type
  179.   { API entry points }
  180.   TFNCallback = function (CallType, Fmt: UINT; Conv: HConv; hsz1, hsz2: HSZ;
  181.     Data: HDDEData; Data1, Data2: DWORD): HDDEData stdcall;
  182.  
  183. const
  184.   CBR_BLOCK = $FFFFFFFF;
  185.  
  186. { DLL registration functions }
  187.  
  188. function DdeInitializeA(var Inst: Longint; Callback: TFNCallback;
  189.   Cmd, Res: Longint): Longint; stdcall;
  190. function DdeInitializeW(var Inst: Longint; Callback: TFNCallback;
  191.   Cmd, Res: Longint): Longint; stdcall;
  192. function DdeInitialize(var Inst: Longint; Callback: TFNCallback;
  193.   Cmd, Res: Longint): Longint; stdcall;
  194.  
  195. const
  196.   { Callback filter flags for use with standard apps. }
  197.  
  198.   CBF_FAIL_SELFCONNECTIONS = $00001000;
  199.   CBF_FAIL_CONNECTIONS = $00002000;
  200.   CBF_FAIL_ADVISES = $00004000;
  201.   CBF_FAIL_EXECUTES = $00008000;
  202.   CBF_FAIL_POKES = $00010000;
  203.   CBF_FAIL_REQUESTS = $00020000;
  204.   CBF_FAIL_ALLSVRXACTIONS = $0003f000;
  205.  
  206.   CBF_SKIP_CONNECT_CONFIRMS = $00040000;
  207.   CBF_SKIP_REGISTRATIONS = $00080000;
  208.   CBF_SKIP_UNREGISTRATIONS = $00100000;
  209.   CBF_SKIP_DISCONNECTS = $00200000;
  210.   CBF_SKIP_ALLNOTIFICATIONS = $003c0000;
  211.  
  212.   { Application command flags }
  213.  
  214.   APPCMD_CLIENTONLY = $00000010;
  215.   APPCMD_FILTERINITS = $00000020;
  216.   APPCMD_MASK = $00000FF0;
  217.  
  218.   { Application classification flags }
  219.  
  220.   APPCLASS_STANDARD = $00000000;
  221.   APPCLASS_MASK = $0000000F;
  222.  
  223. function DdeUninitialize(Inst: DWORD): BOOL; stdcall;
  224.  
  225. { conversation enumeration functions }
  226.  
  227. function DdeConnectList(Inst: DWORD; Service, Topic: HSZ;
  228.   ConvList: HConvList; CC: PConvContext): HConvList; stdcall;
  229. function DdeQueryNextServer(ConvList: HConvList; ConvPrev: HConv): HConv; stdcall;
  230. function DdeDisconnectList(ConvList: HConvList): BOOL; stdcall;
  231.  
  232. { conversation control functions }
  233.  
  234. function DdeConnect(Inst: DWORD; Service, Topic: HSZ;
  235.   CC: PConvContext): HConv; stdcall;
  236. function DdeDisconnect(Conv: HConv): BOOL; stdcall;
  237. function DdeReconnect(Conv: HConv): HConv; stdcall;
  238.  
  239. function DdeQueryConvInfo(Conv: HConv; Transaction: DWORD;
  240.  ConvInfo: PConvInfo): UINT; stdcall;
  241. function DdeSetUserHandle(Conv: HConv; ID, User: DWORD): BOOL; stdcall;
  242.  
  243. function DdeAbandonTransaction(Inst: DWORD; Conv: HConv;
  244.   Transaction: DWORD): BOOL; stdcall;
  245.  
  246. { app server interface functions }
  247.  
  248. function DdePostAdvise(Inst: DWORD; Topic, Item: HSZ): BOOL; stdcall;
  249. function DdeEnableCallback(Inst: DWORD; Conv: HConv; Cmd: UINT): BOOL; stdcall;
  250.  
  251. const
  252.   EC_ENABLEALL = 0;
  253.   EC_ENABLEONE = ST_BLOCKNEXT;
  254.   EC_DISABLE = ST_BLOCKED;
  255.   EC_QUERYWAITING = 2;
  256.  
  257. function DdeNameService(Inst: DWORD; hsz1, hsz2: HSZ; Cmd: UINT): HDDEData; stdcall;
  258.  
  259. const
  260.   DNS_REGISTER = $0001;
  261.   DNS_UNREGISTER = $0002;
  262.   DNS_FILTERON = $0004;
  263.   DNS_FILTEROFF = $0008;
  264.  
  265. { app client interface functions }
  266.  
  267. function DdeClientTransaction(Data: Pointer; DataLen: DWORD;
  268.   Conv: HConv; Item: HSZ; Fmt, DataType: UINT; Timeout: DWORD;
  269.   Result: PDWORD): HDDEData; stdcall;
  270.  
  271. { data transfer functions }
  272.  
  273. function DdeCreateDataHandle(Inst: DWORD; Src: Pointer;
  274.   cb, Off: DWORD; Item: HSZ; Fmt, Cmd: UINT): HDDEData; stdcall;
  275.  
  276. function DdeAddData(Data: HDDEData; Src: Pointer;
  277.   cb, Off: DWORD): HDDEData; stdcall;
  278. function DdeGetData(Data: HDDEData; Dst: Pointer;
  279.   Max, Off: DWORD): DWORD; stdcall;
  280. function DdeAccessData(Data: HDDEData; DataSize: PDWORD): Pointer; stdcall;
  281. function DdeUnaccessData(Data: HDDEData): BOOL; stdcall;
  282. function DdeFreeDataHandle(Data: HDDEData): BOOL; stdcall;
  283.  
  284. const
  285.   HDATA_APPOWNED = $0001;
  286.  
  287. function DdeGetLastError(Inst: DWORD): UINT; stdcall;
  288.  
  289. const
  290.   { error codes }
  291.  
  292.   DMLERR_NO_ERROR = 0;       { must be 0 }
  293.  
  294.   DMLERR_FIRST = $4000;
  295.  
  296.   DMLERR_ADVACKTIMEOUT = $4000;
  297.   DMLERR_BUSY = $4001;
  298.   DMLERR_DATAACKTIMEOUT = $4002;
  299.   DMLERR_DLL_NOT_INITIALIZED = $4003;
  300.   DMLERR_DLL_USAGE = $4004;
  301.   DMLERR_EXECACKTIMEOUT = $4005;
  302.   DMLERR_INVALIDPARAMETER = $4006;
  303.   DMLERR_LOW_MEMORY = $4007;
  304.   DMLERR_MEMORY_ERROR = $4008;
  305.   DMLERR_NOTPROCESSED = $4009;
  306.   DMLERR_NO_CONV_ESTABLISHED = $400a;
  307.   DMLERR_POKEACKTIMEOUT = $400b;
  308.   DMLERR_POSTMSG_FAILED = $400c;
  309.   DMLERR_REENTRANCY = $400D;
  310.   DMLERR_SERVER_DIED = $400E;
  311.   DMLERR_SYS_ERROR = $400F;
  312.   DMLERR_UNADVACKTIMEOUT = $4010;
  313.   DMLERR_UNFOUND_QUEUE_ID = $4011;
  314.  
  315.   DMLERR_LAST = $4011;
  316.  
  317. function DdeCreateStringHandleA(Inst: DWORD; psz: PAnsiChar;
  318.   CodePage: Integer): HSZ; stdcall;
  319. function DdeCreateStringHandleW(Inst: DWORD; psz: PWideChar;
  320.   CodePage: Integer): HSZ; stdcall;
  321. function DdeCreateStringHandle(Inst: DWORD; psz: PChar;
  322.   CodePage: Integer): HSZ; stdcall;
  323. function DdeQueryStringA(Inst: DWORD; HSZ: HSZ; psz: PAnsiChar;
  324.   Max: DWORD; CodePage: Integer): DWORD; stdcall;
  325. function DdeQueryStringW(Inst: DWORD; HSZ: HSZ; psz: PWideChar;
  326.   Max: DWORD; CodePage: Integer): DWORD; stdcall;
  327. function DdeQueryString(Inst: DWORD; HSZ: HSZ; psz: PChar;
  328.   Max: DWORD; CodePage: Integer): DWORD; stdcall;
  329. function DdeFreeStringHandle(Inst: DWORD; HSZ: HSZ): BOOL; stdcall;
  330. function DdeKeepStringHandle(Inst: DWORD; HSZ: HSZ): BOOL; stdcall;
  331. function DdeCmpStringHandles(hsz1, hsz2: HSZ): Integer; stdcall;
  332.  
  333. type
  334.   { DDEML public debugging header file info }
  335.  
  336.   TDdemlMsgHookData = packed record  { new for NT }
  337.     uiLo: UINT;      { unpacked lo and hi parts of lParam }
  338.     uiHi: UINT;
  339.     cbData: DWORD;   { amount of data in message, if any. May be > than 32 bytes. }
  340.     Data: array [0..7] of DWORD; { data peeking by DDESPY is limited to 32 bytes. }
  341.   end;
  342.  
  343.   TMonMsgStruct = packed record
  344.     cb: UINT;
  345.     hWndTo: HWND;
  346.     dwTime: DWORD;
  347.     hTask: THandle;
  348.     wMsg: UINT;
  349.     wParam: WPARAM;
  350.     lParam: LPARAM;
  351.     dmhd: TDdemlMsgHookData;
  352.   end;
  353.  
  354.   TMonCBStruct = packed record
  355.     cb: UINT;
  356.     dwTime: DWORD;
  357.     hTask: THandle;
  358.     dwRet: DWORD;
  359.     wType: UINT;
  360.     wFmt: UINT;
  361.     hConv: HConv;
  362.     hsz1: HSZ;
  363.     hsz2: HSZ;
  364.     hData: HDDEData;
  365.     dwData1: DWORD;
  366.     dwData2: DWORD;
  367.     cc: TConvContext;  { new for NT for XTYP_CONNECT callbacks }
  368.     cbData: DWORD;     { new for NT for data peeking }
  369.     Data: array [0..7] of DWORD; { new for NT for data peeking }
  370.   end;
  371.  
  372.   TMonHSZStructA = packed record
  373.     cb: UINT;
  374.     fsAction: BOOL;    { mh_ value }
  375.     dwTime: DWORD;
  376.     HSZ: HSZ;
  377.     hTask: THandle;
  378.     wReserved: UINT;
  379.     Str: array[0..0] of AnsiChar;
  380.   end;
  381.   TMonHSZStructW = packed record
  382.     cb: UINT;
  383.     fsAction: BOOL;    { mh_ value }
  384.     dwTime: DWORD;
  385.     HSZ: HSZ;
  386.     hTask: THandle;
  387.     wReserved: UINT;
  388.     Str: array[0..0] of WideChar;
  389.   end;
  390.   TMonHSZStruct = TMonHSZStructA;
  391.  
  392. const
  393.   MH_CREATE = 1;
  394.   MH_KEEP = 2;
  395.   MH_DELETE = 3;
  396.   MH_CLEANUP = 4;
  397.  
  398. type
  399.   PMonErrStruct = ^TMonErrStruct;
  400.   TMonErrStruct = packed record
  401.     cb: UINT;
  402.     wLastError: UINT;
  403.     dwTime: DWORD;
  404.     hTask: THandle;
  405.   end;
  406.  
  407.   PMonLinkStruct = ^TMonLinkStruct;
  408.   TMonLinkStruct = packed record
  409.     cb: UINT;
  410.     dwTime: DWORD;
  411.     hTask: THandle;
  412.     fEstablished: BOOL;
  413.     fNoData: BOOL;
  414.     hszSvc: HSz;
  415.     hszTopic: HSz;
  416.     hszItem: HSz;
  417.     wFmt: UINT;
  418.     fServer: BOOL;
  419.     hConvServer: HConv;
  420.     hConvClient: HConv;
  421.   end;
  422.  
  423.   PMonConvStruct = ^TMonConvStruct;
  424.   TMonConvStruct = packed record
  425.     cb: UINT;
  426.     fConnect: BOOL;
  427.     dwTime: DWORD;
  428.     hTask: THandle;
  429.     hszSvc: HSz;
  430.     hszTopic: HSz;
  431.     hConvClient: HConv;
  432.     hConvServer: HConv;
  433.   end;
  434.  
  435. const
  436.   MAX_MONITORS = 4;
  437.   APPCLASS_MONITOR = 1;
  438.   XTYP_MONITOR = $00F0 or XCLASS_NOTIFICATION or XTYPF_NOBLOCK;
  439.  
  440. { Callback filter flags for use with MONITOR apps - 0 implies no monitor
  441.   callbacks. }
  442.  
  443. const
  444.   MF_HSZ_INFO = $01000000;
  445.   MF_SENDMSGS = $02000000;
  446.   MF_POSTMSGS = $04000000;
  447.   MF_CALLBACKS = $08000000;
  448.   MF_ERRORS = $10000000;
  449.   MF_LINKS = $20000000;
  450.   MF_CONV = $40000000;
  451.  
  452.  
  453.   ddelib = 'user32.dll';
  454.  
  455. implementation
  456.  
  457. function DdeInitializeA;         external ddelib name 'DdeInitializeA';
  458. function DdeInitializeW;         external ddelib name 'DdeInitializeW';
  459. function DdeInitialize;         external ddelib name 'DdeInitializeA';
  460. function DdeUninitialize;          external ddelib name 'DdeUninitialize';
  461. function DdeConnectList;           external ddelib name 'DdeConnectList';
  462. function DdeQueryNextServer;       external ddelib name 'DdeQueryNextServer';
  463. function DdeDisconnectList;        external ddelib name 'DdeDisconnectList';
  464. function DdeConnect;               external ddelib name 'DdeConnect';
  465. function DdeDisconnect;            external ddelib name 'DdeDisconnect';
  466. function DdeReconnect;             external ddelib name 'DdeReconnect';
  467. function DdeQueryConvInfo;         external ddelib name 'DdeQueryConvInfo';
  468. function DdeSetUserHandle;         external ddelib name 'DdeSetUserHandle';
  469. function DdeAbandonTransaction;    external ddelib name 'DdeAbandonTransaction';
  470. function DdePostAdvise;            external ddelib name 'DdePostAdvise';
  471. function DdeEnableCallback;        external ddelib name 'DdeEnableCallback';
  472. function DdeNameService;           external ddelib name 'DdeNameService';
  473. function DdeClientTransaction;     external ddelib name 'DdeClientTransaction';
  474. function DdeCreateDataHandle;      external ddelib name 'DdeCreateDataHandle';
  475. function DdeAddData;               external ddelib name 'DdeAddData';
  476. function DdeGetData;               external ddelib name 'DdeGetData';
  477. function DdeAccessData;            external ddelib name 'DdeAccessData';
  478. function DdeUnaccessData;          external ddelib name 'DdeUnaccessData';
  479. function DdeFreeDataHandle;        external ddelib name 'DdeFreeDataHandle';
  480. function DdeGetLastError;          external ddelib name 'DdeGetLastError';
  481. function DdeCreateStringHandleA; external ddelib name 'DdeCreateStringHandleA';
  482. function DdeCreateStringHandleW; external ddelib name 'DdeCreateStringHandleW';
  483. function DdeCreateStringHandle; external ddelib name 'DdeCreateStringHandleA';
  484. function DdeQueryStringA;        external ddelib name 'DdeQueryStringA';
  485. function DdeQueryStringW;        external ddelib name 'DdeQueryStringW';
  486. function DdeQueryString;        external ddelib name 'DdeQueryStringA';
  487. function DdeFreeStringHandle;      external ddelib name 'DdeFreeStringHandle';
  488. function DdeKeepStringHandle;      external ddelib name 'DdeKeepStringHandle';
  489. function DdeCmpStringHandles;      external ddelib name 'DdeCmpStringHandles';
  490.  
  491. end.
  492.