home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / ddeml / msngr / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  4.3 KB  |  196 lines

  1. /****************************** Module Header ******************************\
  2. * Module Name:  util.c
  3. *
  4. * Utility functions used by msngr app.
  5. *
  6. * Created:  1/1/89  sanfords
  7. *
  8. * Copyright (c) 1988, 1989  Microsoft Corporation
  9. \***************************************************************************/
  10. #include "msngr.h"
  11.  
  12. extern NPUSERLIST gnpUL;
  13. extern HAB hab;
  14.  
  15. /***************************** Public  Function ****************************\
  16. * Concatonates psz1 and psz2 into pszDest.
  17. *
  18. * History:  1/1/89  created sanfords
  19. \***************************************************************************/
  20. void lstrcat(pszDest, psz1, psz2)
  21. PSZ pszDest, psz1, psz2;
  22. {
  23.     while (*psz1 != '\0') {
  24.         *pszDest++ = *psz1++;
  25.     }
  26.     while (*psz2 != '\0') {
  27.         *pszDest++ = *psz2++;
  28.     }
  29.     *pszDest = '\0';
  30. }
  31.  
  32.  
  33. void lstrcpy(pszDst, pszSrc)
  34. PSZ pszDst, pszSrc;
  35. {
  36.     lstrcat(pszDst, pszSrc, "");
  37. }
  38.  
  39.  
  40. /***************************** Public  Function ****************************\
  41. * Concatonates psz1 and psz2 into pszDest but leaves a '\0' in between.
  42. *
  43. * History:  1/1/89  created sanfords
  44. \***************************************************************************/
  45. void lstrpak(pszDest, psz1, psz2)
  46. PSZ pszDest, psz1, psz2;
  47. {
  48.     while (*psz1 != '\0') {
  49.         *pszDest++ = *psz1++;
  50.     }
  51.     *pszDest++ = '\0';
  52.     while (*psz2 != '\0') {
  53.         *pszDest++ = *psz2++;
  54.     }
  55.     *pszDest = '\0';
  56. }
  57. /***************************** Private Function ****************************\
  58. *
  59. * returns string length not counting null terminator.
  60. *
  61. * History:  1/1/89  created     sanfords
  62. \***************************************************************************/
  63. int lstrlen(psz)
  64. PSZ psz;
  65. {
  66.     int c = 0;
  67.  
  68.     while (*psz != 0) {
  69.         psz++;
  70.         c++;
  71.     }
  72.     return(c);
  73. }
  74.  
  75.  
  76.  
  77. /***************************** Private Function ****************************\
  78. * DESCRIPTION:
  79. *   These functions handle hConv-hsz relationship control.
  80. *
  81. * History:      8/23/89 Created         sanfords
  82. \***************************************************************************/
  83. void DestroyUser(npUL)
  84. NPUSERLIST npUL;
  85. {
  86.     PNPUSERLIST ppList;
  87.     
  88.     ppList = &gnpUL;
  89.     while (*ppList && *ppList != npUL) {
  90.         ppList = &((*ppList)->next);
  91.     }
  92.     if (!ppList) {
  93.         return;
  94.     }
  95.     DdeFreeHsz((*ppList)->hsz);
  96.     if (WinIsWindow(hab, (*ppList)->hwndLink))
  97.         WinDestroyWindow((*ppList)->hwndLink);
  98.     if ((*ppList)->hConvMsg) {
  99.         DdeDisconnect((*ppList)->hConvMsg);
  100.     }
  101.     freeUserList(ppList);
  102. }
  103.  
  104.  
  105. /***************************** Private Function ****************************\
  106. * DESCRIPTION:
  107. *   These functions handle hConv-hsz relationship control.
  108. *
  109. * History:      1/13/89 Created         sanfords
  110. \***************************************************************************/
  111. VOID AddUser(
  112. HCONV hConvMsg,
  113. HSZ hsz,
  114. HAPP hApp)
  115. {
  116.     NPUSERLIST pList;
  117.     UCHAR sz[MAX_NAMESTR + 1];
  118.     SHORT lit;
  119.     extern HWND hwndLB;
  120.  
  121.     if ((pList = (NPUSERLIST)WinAllocMem(hheap, sizeof(USERLIST))) == 0)
  122.         return;
  123.     pList->hConvMsg = hConvMsg;
  124.     pList->hConvLink = 0;
  125.     pList->hwndLink = NULL;
  126.     pList->hsz = hsz;
  127.     pList->hApp = hApp;
  128.     pList->next = gnpUL;  /* link in front */
  129.     gnpUL = pList;
  130.     DdeGetHszString(hsz, sz, MAX_NAMESTR + 1L);
  131.     lit = (SHORT)WinSendMsg(hwndLB, LM_INSERTITEM,
  132.             MPFROMSHORT(LIT_SORTASCENDING), MPFROMP(sz));
  133.     WinSendMsg(hwndLB, LM_SETITEMHANDLE, (MPARAM)lit, (MPARAM)pList);
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140. NPUSERLIST FindUser(pList, hsz)
  141. NPUSERLIST pList;
  142. HSZ hsz;
  143. {
  144.     while (pList) {
  145.         if (hsz == pList->hsz)
  146.             return(pList);
  147.         pList = pList->next;
  148.     }
  149.     return(0);
  150.  
  151. }
  152.  
  153.  
  154.  
  155.  
  156. void freeUserList(ppList)
  157. PNPUSERLIST ppList;
  158. {
  159.     NPUSERLIST pListT;
  160.  
  161.     while (*ppList) {
  162.         pListT = *ppList;
  163.         *ppList = pListT->next;
  164.         WinFreeMem(hheap, (NPBYTE)pListT, sizeof(USERLIST));
  165.     }
  166. }
  167.  
  168.  
  169.  
  170.  
  171. PVOID FarAllocMem(hheap, cb)
  172. HHEAP hheap;
  173. USHORT cb;
  174. {
  175.     return((PVOID)((PBYTE)WinLockHeap(hheap) + (USHORT)WinAllocMem(hheap, cb)));
  176. }
  177.  
  178.  
  179.  
  180. void MyPostError(err)
  181. USHORT err;
  182. {
  183.     switch (err) {
  184.     case DMGERR_SERVER_DIED:
  185.     case DMGERR_NO_CONV_ESTABLISHED:
  186.         break;
  187.     default:
  188.         DdePostError(err);
  189.         break;
  190.     }
  191. }
  192.  
  193.  
  194.  
  195.  
  196.