home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 18.ddi / SAMPLES / DDEML / CLOCK / WRAPPER.C_ / WRAPPER.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  16.6 KB  |  585 lines

  1. /***************************************************************************\
  2.  
  3.    PROGRAM     : wrapper.c
  4.  
  5.    PURPOSE     : This is not a full program but a module you can include
  6.                  in your code.  It implements a standard DDEML callback
  7.                  function that allows you to have most of your DDE table
  8.                  driven.  The default callback function handles all basic
  9.                  System Topic information based on the tables you give
  10.                  to this app.
  11.  
  12.    LIMITATIONS : This only supports servers that:
  13.                  have only one service name
  14.                  have enumerable topics and items
  15.                  do not change the topics or items they support over time.
  16.  
  17.  
  18.    EXPORTED ROUTINES:
  19.  
  20.     InitializeDDE()
  21.         Use this to initialize the callback function tables and the DDEML
  22.  
  23.     UninitializeDDE()
  24.         Use this to cleanup this module and uninitialize the DDEML instance.
  25.  
  26. \***************************************************************************/
  27.  
  28. #include <windows.h>
  29. #include <ddeml.h>
  30. #include <string.h>
  31. #include "wrapper.h"
  32.  
  33.  
  34. VOID InitHszs(LPDDESERVICETBL psi);
  35. WORD GetFormat(LPSTR pszFormat);
  36. VOID FreeHszs(LPDDESERVICETBL psi);
  37. HDDEDATA EXPENTRY __export WrapperCallback(WORD wType, WORD wFmt, HCONV hConv, HSZ hsz1,
  38.         HSZ hsz2, HDDEDATA hData, DWORD dwData1, DWORD dwData2);
  39. BOOL DoCallback(HSZ hszTopic, HSZ hszItem, WORD wFmt, WORD wType,
  40.         HDDEDATA hDataIn, LPDDESERVICETBL psi, HDDEDATA *phDataRet);
  41. HDDEDATA ReqItems(HDDEDATA hDataOut, LPDDETOPICTBL ptpc);
  42. HDDEDATA AddReqFormat(HDDEDATA hDataOut, LPSTR pszFmt);
  43. HDDEDATA ReqFormats(HDDEDATA hDataOut, LPDDETOPICTBL ptpc);
  44. HDDEDATA DoWildConnect(HSZ hszTopic);
  45.  
  46. PFNCALLBACK lpfnUserCallback = NULL;
  47. PFNCALLBACK lpfnWrapperCallback = NULL;
  48. DWORD idInst;
  49. LPDDESERVICETBL pasi;
  50. char tab[] = "\t";
  51.  
  52. #define FOR_EACH_TOPIC(psvc, ptpc, i)  for (i = 0, ptpc=(psvc)->topic; i < (int)(psvc)->cTopics; i++, ptpc++)
  53. #define FOR_EACH_ITEM(ptpc, pitm, i)   for (i = 0, pitm=(ptpc)->item;  i < (int)(ptpc)->cItems;  i++, pitm++)
  54. #define FOR_EACH_FORMAT(pitm, pfmt, i) for (i = 0, pfmt=(pitm)->fmt;   i < (int)(pitm)->cFormats;i++, pfmt++)
  55.  
  56.  
  57.  
  58. /*     STANDARD PREDEFINED FORMATS     */
  59.  
  60. #define CSTDFMTS    9
  61. struct {
  62.     WORD wFmt;
  63.     PSTR pszFmt;
  64. } StdFmts[CSTDFMTS] = {
  65.     {   CF_TEXT        ,  "TEXT"          } ,
  66.     {   CF_BITMAP      ,  "BITMAP"        } ,
  67.     {   CF_METAFILEPICT,  "METAFILEPICT"  } ,
  68.     {   CF_SYLK        ,  "SYLK"          } ,
  69.     {   CF_DIF         ,  "DIF"           } ,
  70.     {   CF_TIFF        ,  "TIFF"          } ,
  71.     {   CF_OEMTEXT     ,  "OEMTEXT"       } ,
  72.     {   CF_DIB         ,  "DIB"           } ,
  73.     {   CF_PALETTE     ,  "PALETTE"       } ,
  74. };
  75.  
  76.  
  77.  
  78. HDDEDATA PASCAL SysReqTopics(HDDEDATA hDataOut);
  79. HDDEDATA PASCAL SysReqSysItems(HDDEDATA hDataOut);
  80. HDDEDATA PASCAL SysReqFormats(HDDEDATA hDataOut);
  81.  
  82.        /*      STANDARD SERVICE INFO TABLES        */
  83.  
  84. DDEFORMATTBL StdSvcSystopicTopicsFormats[] = {
  85.     "TEXT", 0, 0, NULL, SysReqTopics
  86. };
  87.  
  88. DDEFORMATTBL StdSvcSystopicSysitemsFormats[] = {
  89.     "TEXT", 0, 0, NULL, SysReqSysItems
  90. };
  91.  
  92. DDEFORMATTBL StdSvcSystopicFormatsFormats[] = {
  93.     "TEXT", 0, 0, NULL, SysReqFormats
  94. };
  95.  
  96. #define ITPC_TOPICS     0
  97. #define ITPC_SYSITEMS   1
  98. #define ITPC_FORMATS    2
  99. #define ITPC_ITEMLIST   3
  100.  
  101. #define ITPC_COUNT      4
  102.  
  103. DDEITEMTBL StdSvcSystopicItems[] = {
  104.     { SZDDESYS_ITEM_TOPICS,   0, NULL, 1, 0, StdSvcSystopicTopicsFormats   },
  105.     { SZDDESYS_ITEM_SYSITEMS, 0, NULL, 1, 0, StdSvcSystopicSysitemsFormats },
  106.     { SZDDESYS_ITEM_FORMATS,  0, NULL, 1, 0, StdSvcSystopicFormatsFormats  },
  107.     { SZDDE_ITEM_ITEMLIST,    0, NULL, 1, 0, StdSvcSystopicSysitemsFormats },
  108. };
  109.  
  110. DDETOPICTBL StdSvc[] = {
  111.     SZDDESYS_TOPIC, 0, ITPC_COUNT, 0, StdSvcSystopicItems
  112. };
  113.  
  114. DDESERVICETBL SSI = {
  115.     NULL, 0, 1, 0, StdSvc
  116. };
  117.  
  118. /*********************************************************************/
  119.  
  120.  
  121. BOOL InitializeDDE(
  122. PFNCALLBACK lpfnCustomCallback,
  123. LPDWORD pidInst,
  124. LPDDESERVICETBL AppSvcInfo,
  125. DWORD dwFilterFlags,
  126. HANDLE hInst)
  127. {
  128.     if (lpfnCustomCallback) {
  129.         lpfnUserCallback = (PFNCALLBACK)MakeProcInstance((FARPROC)lpfnCustomCallback, hInst);
  130.     }
  131.     lpfnWrapperCallback = (PFNCALLBACK)MakeProcInstance((FARPROC)WrapperCallback, hInst);
  132.     if (DdeInitialize(&idInst, lpfnWrapperCallback, dwFilterFlags, 0)) {
  133.         if (lpfnCustomCallback) {
  134.             FreeProcInstance((FARPROC)lpfnUserCallback);
  135.         }
  136.         FreeProcInstance((FARPROC)lpfnWrapperCallback);
  137.         return(FALSE);
  138.     }
  139.     InitHszs(AppSvcInfo);
  140.     InitHszs(&SSI);
  141.     pasi = AppSvcInfo;
  142.     DdeNameService(idInst, pasi->hszService, 0, DNS_REGISTER);
  143.     return(TRUE);
  144. }
  145.  
  146.  
  147.  
  148. VOID InitHszs(
  149. LPDDESERVICETBL psi)
  150. {
  151.     int iTopic, iItem, iFmt;
  152.     LPDDETOPICTBL ptpc;
  153.     LPDDEITEMTBL pitm;
  154.     LPDDEFORMATTBL pfmt;
  155.  
  156.     if (psi->pszService) {
  157.         psi->hszService = DdeCreateStringHandle(idInst, psi->pszService, 0);
  158.     }
  159.     FOR_EACH_TOPIC(psi, ptpc, iTopic) {
  160.         ptpc->hszTopic = DdeCreateStringHandle(idInst, ptpc->pszTopic, 0);
  161.         FOR_EACH_ITEM(ptpc, pitm, iItem) {
  162.             pitm->hszItem = DdeCreateStringHandle(idInst, pitm->pszItem, 0);
  163.             FOR_EACH_FORMAT(pitm, pfmt, iFmt) {
  164.                 pfmt->wFmt = GetFormat(pfmt->pszFormat);
  165.             }
  166.         }
  167.     }
  168. }
  169.  
  170.  
  171. /*
  172.  * This function allows apps to use standard CF_ formats.  The string
  173.  * given may be in the StdFmts[] table.
  174.  */
  175.  
  176. WORD GetFormat(
  177. LPSTR pszFormat)
  178. {
  179.     int iFmt;
  180.  
  181.     for (iFmt = 0; iFmt < CSTDFMTS; iFmt++) {
  182.         if (!lstrcmp(pszFormat, StdFmts[iFmt].pszFmt)) {
  183.             return(StdFmts[iFmt].wFmt);
  184.         }
  185.     }
  186.     return(RegisterClipboardFormat(pszFormat));
  187. }
  188.  
  189.  
  190.  
  191. VOID UninitializeDDE()
  192. {
  193.     DdeNameService(idInst, pasi->hszService, 0, DNS_UNREGISTER);
  194.     FreeHszs(pasi);
  195.     FreeHszs(&SSI);
  196.     DdeUninitialize(idInst);
  197.     if (lpfnUserCallback) {
  198.         FreeProcInstance((FARPROC)lpfnUserCallback);
  199.     }
  200.     FreeProcInstance((FARPROC)lpfnWrapperCallback);
  201. };
  202.  
  203.  
  204.  
  205. VOID FreeHszs(
  206. LPDDESERVICETBL psi)
  207. {
  208.     int iTopic, iItem;
  209.     LPDDETOPICTBL ptpc;
  210.     LPDDEITEMTBL pitm;
  211.  
  212.     DdeFreeStringHandle(idInst, psi->hszService);
  213.     FOR_EACH_TOPIC(psi, ptpc, iTopic) {
  214.         DdeFreeStringHandle(idInst, ptpc->hszTopic);
  215.         FOR_EACH_ITEM(ptpc, pitm, iItem) {
  216.             DdeFreeStringHandle(idInst, pitm->hszItem);
  217.         }
  218.     }
  219. }
  220.  
  221.  
  222.  
  223. HDDEDATA EXPENTRY __export WrapperCallback(
  224. WORD wType,
  225. WORD wFmt,
  226. HCONV hConv,
  227. HSZ hsz1,
  228. HSZ hsz2,
  229. HDDEDATA hData,
  230. DWORD dwData1,
  231. DWORD dwData2)
  232. {
  233.     HDDEDATA hDataRet;
  234.  
  235.     switch (wType) {
  236.     case XTYP_WILDCONNECT:
  237.         if (!hsz2 || !DdeCmpStringHandles(hsz2, pasi->hszService)) {
  238.             return(DoWildConnect(hsz1));
  239.         }
  240.         break;
  241.  
  242.     case XTYP_ADVSTART:
  243.     case XTYP_CONNECT:
  244.     case XTYP_EXECUTE:
  245.     case XTYP_REQUEST:
  246.     case XTYP_ADVREQ:
  247.     case XTYP_ADVDATA:
  248.     case XTYP_POKE:
  249.  
  250.         if(DoCallback(hsz1, hsz2, wFmt, wType, hData,
  251.                 &SSI, &hDataRet))
  252.             return(hDataRet);
  253.  
  254.         if (DoCallback(hsz1, hsz2, wFmt, wType, hData,
  255.                 pasi, &hDataRet))
  256.             return(hDataRet);
  257.  
  258.         /* Fall Through */
  259.     default:
  260.         if (lpfnUserCallback != NULL) {
  261.             return(lpfnUserCallback(wType, wFmt, hConv, hsz1, hsz2, hData,
  262.                 dwData1, dwData2));
  263.         }
  264.     }
  265.     return(0);
  266. }
  267.  
  268.  
  269.  
  270.  
  271. BOOL DoCallback(
  272. HSZ hszTopic,
  273. HSZ hszItem,
  274. WORD wFmt,
  275. WORD wType,
  276. HDDEDATA hDataIn,
  277. LPDDESERVICETBL psi,
  278. HDDEDATA *phDataRet)
  279. {
  280.     int iTopic, iItem, iFmt;
  281.     LPDDEFORMATTBL pfmt;
  282.     LPDDEITEMTBL pitm;
  283.     LPDDETOPICTBL ptpc;
  284.  
  285.     FOR_EACH_TOPIC(psi, ptpc, iTopic) {
  286.         if (DdeCmpStringHandles(ptpc->hszTopic, hszTopic))
  287.             continue;
  288.  
  289.         if (wType == XTYP_CONNECT) {
  290.             *phDataRet = (HDDEDATA)TRUE;
  291.             return(TRUE);
  292.         }
  293.  
  294.         FOR_EACH_ITEM(ptpc, pitm, iItem) {
  295.             if (DdeCmpStringHandles(pitm->hszItem, hszItem))
  296.                 continue;
  297.  
  298.             if (wType == XTYP_EXECUTE) {
  299.                 if (pitm->lpfnExecute) {
  300.                     if ((*pitm->lpfnExecute)(hDataIn))
  301.                         *phDataRet = (HDDEDATA)DDE_FACK;
  302.                 } else {
  303.                     *phDataRet = (HDDEDATA)DDE_FNOTPROCESSED;
  304.                 }
  305.                 return(TRUE);
  306.             }
  307.  
  308.             FOR_EACH_FORMAT(pitm, pfmt, iFmt) {
  309.                 if (pfmt->wFmt != wFmt)
  310.                     continue;
  311.  
  312.                 switch (wType) {
  313.                 case XTYP_ADVSTART:
  314.                     *phDataRet = (HDDEDATA)TRUE;
  315.                     break;
  316.  
  317.                 case XTYP_ADVDATA:
  318.                 case XTYP_POKE:
  319.                     if (pfmt->lpfnPoke) {
  320.                         if ((*pfmt->lpfnPoke)(hDataIn)) {
  321.                             *phDataRet = (HDDEDATA)DDE_FACK;
  322.                             DdePostAdvise(idInst, hszTopic, hszItem);
  323.                         }
  324.                     } else {
  325.                         *phDataRet = (HDDEDATA)DDE_FNOTPROCESSED;
  326.                     }
  327.                     break;
  328.  
  329.                 case XTYP_REQUEST:
  330.                 case XTYP_ADVREQ:
  331.                     if (pfmt->lpfnRequest) {
  332.                         HDDEDATA hDataOut;
  333.  
  334.                         hDataOut = DdeCreateDataHandle(idInst, NULL, 0, 0, pitm->hszItem,
  335.                                 pfmt->wFmt, 0);
  336.                         *phDataRet = (HDDEDATA)(*pfmt->lpfnRequest)(hDataOut);
  337.                         if (!*phDataRet) {
  338.                             DdeFreeDataHandle(hDataOut);
  339.                         }
  340.                     } else {
  341.                         *phDataRet = 0;
  342.                     }
  343.                     break;
  344.                 }
  345.                 return(TRUE);
  346.             }
  347.         }
  348.  
  349.         /* item not found in tables */
  350.  
  351.         if (wFmt == CF_TEXT && (wType == XTYP_REQUEST || wType == XTYP_ADVREQ)) {
  352.             /*
  353.              * If formats item was requested and not found in the tables,
  354.              * return a list of formats supported under this topic.
  355.              */
  356.             if (!DdeCmpStringHandles(hszItem, SSI.topic[0].item[ITPC_FORMATS].hszItem)) {
  357.                 *phDataRet = DdeCreateDataHandle(idInst, NULL, 0, 0, hszItem, wFmt, 0);
  358.                 *phDataRet = ReqFormats(*phDataRet, ptpc);
  359.                 return(TRUE);
  360.             }
  361.             /*
  362.              * If sysitems or topicitemlist item was requested and not found,
  363.              * return a list of items supported under this topic.
  364.              */
  365.             if (!DdeCmpStringHandles(hszItem, SSI.topic[0].item[ITPC_SYSITEMS].hszItem) ||
  366.                 !DdeCmpStringHandles(hszItem, SSI.topic[0].item[ITPC_ITEMLIST].hszItem)) {
  367.                 *phDataRet = ReqItems(DdeCreateDataHandle(idInst, NULL, 0, 0, hszItem, wFmt, 0), ptpc);
  368.                 return(TRUE);
  369.             }
  370.         }
  371.     }
  372.  
  373.     /* no topics fit */
  374.  
  375.     return(FALSE);
  376. }
  377.  
  378.  
  379. /*
  380.  * These are Request routines for supporting the system topic.
  381.  * Their behavior depends on the table contents.
  382.  */
  383.  
  384. HDDEDATA PASCAL SysReqTopics(
  385. HDDEDATA hDataOut)         // data handle to add output data to.
  386. {
  387.     int iTopic, cb, cbOff;
  388.     LPDDETOPICTBL ptpc;
  389.  
  390.     /*
  391.      * This code assumes SSI only contains the system topic.
  392.      */
  393.  
  394.     cbOff = 0;
  395.     FOR_EACH_TOPIC(pasi, ptpc, iTopic) {
  396.         if (!DdeCmpStringHandles(ptpc->hszTopic, SSI.topic[0].hszTopic)) {
  397.             continue;       // don't add systopic twice.
  398.         }
  399.         cb = lstrlen(ptpc->pszTopic);
  400.         hDataOut = DdeAddData(hDataOut, ptpc->pszTopic, (DWORD)cb, (DWORD)cbOff);
  401.         cbOff += cb;
  402.         hDataOut = DdeAddData(hDataOut, (LPBYTE)&tab, (DWORD)1, (DWORD)cbOff);
  403.         cbOff++;
  404.     }
  405.  
  406.     hDataOut = DdeAddData(hDataOut, SSI.topic[0].pszTopic,
  407.             (DWORD)lstrlen(SSI.topic[0].pszTopic) + 1, (DWORD)cbOff);
  408.  
  409.     return(hDataOut);
  410. }
  411.  
  412.  
  413.  
  414. HDDEDATA PASCAL SysReqSysItems(
  415. HDDEDATA hDataOut)
  416. {
  417.     return(ReqItems(hDataOut, &SSI.topic[ITPC_SYSITEMS]));
  418. }
  419.  
  420.  
  421. /*
  422.  * Given a topic table, this function returns a tab delimited list of
  423.  * items supported under that topic.
  424.  */
  425. HDDEDATA ReqItems(
  426. HDDEDATA hDataOut,
  427. LPDDETOPICTBL ptpc)
  428. {
  429.     int cb, iItem, cbOff = 0;
  430.     LPDDEITEMTBL pitm;
  431.  
  432.     /*
  433.      * return a list of all the items within this topic
  434.      */
  435.     FOR_EACH_ITEM(ptpc, pitm, iItem) {
  436.         cb = lstrlen(pitm->pszItem);
  437.         hDataOut = DdeAddData(hDataOut, pitm->pszItem, (DWORD)cb, (DWORD)cbOff);
  438.         cbOff += cb;
  439.         hDataOut = DdeAddData(hDataOut, (LPBYTE)&tab, (DWORD)1, (DWORD)cbOff);
  440.         cbOff++;
  441.     }
  442.  
  443.  
  444.     /*
  445.      * if this is for the System Topic, add to the list our default items.
  446.      */
  447.  
  448.     if (!DdeCmpStringHandles(ptpc->hszTopic, SSI.topic[0].hszTopic)) {
  449.         ptpc = &SSI.topic[0];
  450.         FOR_EACH_ITEM(ptpc, pitm, iItem) {
  451.             cb = lstrlen(pitm->pszItem);
  452.             hDataOut = DdeAddData(hDataOut, pitm->pszItem, (DWORD)cb, (DWORD)cbOff);
  453.             cbOff += cb;
  454.             hDataOut = DdeAddData(hDataOut, (LPBYTE)&tab, (DWORD)1, (DWORD)cbOff);
  455.             cbOff++;
  456.         }
  457.     } else {
  458.         /*
  459.          * Add the standard TopicListItems and SysItem items.
  460.          */
  461.         cb = lstrlen(SSI.topic[0].item[ITPC_SYSITEMS].pszItem);
  462.         hDataOut = DdeAddData(hDataOut,
  463.             SSI.topic[0].item[ITPC_SYSITEMS].pszItem, (DWORD)cb, (DWORD)cbOff);
  464.         cbOff += cb;
  465.         hDataOut = DdeAddData(hDataOut, (LPBYTE)&tab, (DWORD)1, (DWORD)cbOff);
  466.         cbOff++;
  467.  
  468.         cb = lstrlen(SSI.topic[0].item[ITPC_ITEMLIST].pszItem);
  469.         hDataOut = DdeAddData(hDataOut,
  470.             SSI.topic[0].item[ITPC_ITEMLIST].pszItem, (DWORD)cb, (DWORD)cbOff);
  471.         cbOff += cb;
  472.         hDataOut = DdeAddData(hDataOut, (LPBYTE)&tab, (DWORD)1, (DWORD)cbOff);
  473.         cbOff++;
  474.  
  475.         cb = lstrlen(SSI.topic[0].item[ITPC_FORMATS].pszItem);
  476.         hDataOut = DdeAddData(hDataOut,
  477.             SSI.topic[0].item[ITPC_FORMATS].pszItem, (DWORD)cb, (DWORD)cbOff);
  478.         cbOff += cb;
  479.         hDataOut = DdeAddData(hDataOut, (LPBYTE)&tab, (DWORD)1, (DWORD)cbOff);
  480.         cbOff++;
  481.     }
  482.  
  483.     hDataOut = DdeAddData(hDataOut, '\0', (DWORD)1, (DWORD)--cbOff);
  484.     return(hDataOut);
  485. }
  486.  
  487.  
  488.  
  489.  
  490. HDDEDATA PASCAL SysReqFormats(
  491. HDDEDATA hDataOut)
  492. {
  493.     int iTopic, iItem, iFmt;
  494.     LPDDETOPICTBL ptpc;
  495.     LPDDEITEMTBL pitm;
  496.     LPDDEFORMATTBL pfmt;
  497.  
  498.     hDataOut = DdeAddData(hDataOut, (LPBYTE)"TEXT", 5, 0);
  499.     FOR_EACH_TOPIC(pasi, ptpc, iTopic) {
  500.         FOR_EACH_ITEM(ptpc, pitm, iItem) {
  501.             FOR_EACH_FORMAT(pitm, pfmt, iFmt) {
  502.                 hDataOut = AddReqFormat(hDataOut, pfmt->pszFormat);
  503.             }
  504.         }
  505.     }
  506.     return(hDataOut);
  507. }
  508.  
  509.  
  510.  
  511. HDDEDATA AddReqFormat(
  512. HDDEDATA hDataOut,
  513. LPSTR pszFmt)
  514. {
  515.     LPSTR pszList;
  516.     DWORD cbOff;
  517.  
  518.     pszList = DdeAccessData(hDataOut, NULL);
  519.     if (_fstrstr(pszList, pszFmt) == NULL) {
  520.         cbOff = lstrlen(pszList);
  521.         DdeUnaccessData(hDataOut);
  522.         hDataOut = DdeAddData(hDataOut, (LPBYTE)&tab, 1, cbOff++);
  523.         hDataOut = DdeAddData(hDataOut, (LPBYTE)pszFmt, lstrlen(pszFmt) + 1, cbOff);
  524.     } else {
  525.         DdeUnaccessData(hDataOut);
  526.     }
  527.  
  528.     return(hDataOut);
  529. }
  530.  
  531.  
  532. HDDEDATA ReqFormats(
  533. HDDEDATA hDataOut,
  534. LPDDETOPICTBL ptpc)
  535. {
  536.     int iItem, iFmt;
  537.     LPDDEITEMTBL pitm;
  538.     LPDDEFORMATTBL pfmt;
  539.  
  540.     hDataOut = DdeAddData(hDataOut, "", 1, 0);
  541.     FOR_EACH_ITEM(ptpc, pitm, iItem) {
  542.         FOR_EACH_FORMAT(pitm, pfmt, iFmt) {
  543.             hDataOut = AddReqFormat(hDataOut, pfmt->pszFormat);
  544.         }
  545.     }
  546.     return(hDataOut);
  547. }
  548.  
  549.  
  550.  
  551. HDDEDATA DoWildConnect(
  552. HSZ hszTopic)
  553. {
  554.     LPDDETOPICTBL ptpc;
  555.     HDDEDATA hData;
  556.     PHSZPAIR pHszPair;
  557.     int iTopic, cTopics = 2;
  558.  
  559.     if (!hszTopic) {
  560.         cTopics += pasi->cTopics;
  561.     }
  562.  
  563.     hData = DdeCreateDataHandle(idInst, NULL, cTopics * sizeof(HSZPAIR), 0, NULL, 0, 0);
  564.     pHszPair = (HSZPAIR FAR *)DdeAccessData(hData, NULL);
  565.     pHszPair->hszSvc = pasi->hszService;
  566.     pHszPair->hszTopic = SSI.topic[0].hszTopic;  // always support systopic.
  567.     pHszPair++;
  568.     ptpc = &pasi->topic[0];
  569.     FOR_EACH_TOPIC(pasi, ptpc, iTopic) {
  570.         if (hszTopic && DdeCmpStringHandles(hszTopic, ptpc->hszTopic)) {
  571.             continue;
  572.         }
  573.         if (!DdeCmpStringHandles(ptpc->hszTopic, SSI.topic[0].hszTopic)) {
  574.             continue;       // don't enter systopic twice.
  575.         }
  576.         pHszPair->hszSvc = pasi->hszService;
  577.         pHszPair->hszTopic = ptpc->hszTopic;
  578.         pHszPair++;
  579.     }
  580.     pHszPair->hszSvc = 0;
  581.     pHszPair->hszTopic = 0;
  582.     DdeUnaccessData(hData);
  583.     return(hData);
  584. }
  585.