home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / com / zocdev / pip / pipsockt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-30  |  4.1 KB  |  144 lines

  1. /***********************************************************************
  2. *                                                                      *
  3. *   This file is provided on an AS-IS basis.                           *
  4. *   It shows how to access a PIPDLL from the socket side.              *
  5. *   It is not complete, so (of course) it will not compile             *
  6. *                                                                      *
  7. *   ------------------------------------------------------------------ *
  8. *                                                                      *
  9. *   No copyright by Markus Schmidt, 1993                               *
  10. *                                                                      *
  11. ***********************************************************************/
  12.  
  13. #define INCL_WINMESSAGEMGR
  14. #define INCL_WINWINDOWMGR
  15. #define INCL_WINDIALOGS
  16.  
  17. #define INCL_DOSMODULEMGR
  18. #define INCL_DOSFILEMGR
  19. #define INCL_DOSPROCESS
  20.  
  21. #define INCL_NOCOMMON
  22. #include <os2.h>
  23. #include <string.h>
  24.  
  25. #define PIP_INCL_SOCKET
  26. #include "pip.h"
  27.  
  28.  
  29.  
  30. int main(void);
  31. int pipInitSocket(unsigned char *dllname, PIP_SOCKET *, PIP_PLUG *);
  32. void InfoMsg(char *txt);
  33. void ErrorMsg(char *txt);
  34.  
  35. static PIP_SOCKET pipSocket= { 0, };
  36. static PIP_PLUG   pipPlug=   { 0, };
  37. static HAB hab;
  38. static HMQ hmq;
  39.  
  40.  
  41. int main()
  42. {
  43.     int rc;
  44.     hab = WinInitialize(0);             /* Initialize PM  */
  45.     hmq = WinCreateMsgQueue(hab, 0);    /* Create a message queue */
  46.  
  47.     rc= pipInitSocket("PIPASCII", &pipSocket, &pipPlug);
  48.     if (rc==PIP_OK) {
  49.         rc= pipPlug.pipIntro(&pipSocket, &pipPlug);
  50.         rc= pipPlug.pipInit(&pipSocket, &pipPlug);
  51.         rc= pipPlug.pipSetup(&pipSocket, &pipPlug);
  52.         rc= pipPlug.pipSend(&pipSocket, &pipPlug, NULL, NULL);
  53.         rc= pipPlug.pipReceive(&pipSocket, &pipPlug, NULL, NULL);
  54.         rc= pipPlug.pipCleanup(&pipSocket, &pipPlug);
  55.     }
  56.  
  57.     WinDestroyMsgQueue(hmq);
  58.     WinTerminate(hab);
  59.  
  60.     return (0);
  61. }
  62.  
  63. int pipInitSocket(unsigned char *dllname, PIP_SOCKET *pxs, PIP_PLUG *pxp)
  64. {
  65.     HMODULE hmDll;
  66.     int rc;
  67.  
  68.     rc= DosLoadModule("", 0, dllname, &hmDll);
  69.     if (rc!=0) 
  70.         return (PIP_ERROR);
  71.  
  72.     // Load adresses into plug
  73.     rc+= DosQueryProcAddr(hmDll, 0,"pipIntro",  &(pxp->pipIntro));
  74.     rc+= DosQueryProcAddr(hmDll, 0,"pipInit",  &(pxp->pipInit));
  75.     rc+= DosQueryProcAddr(hmDll, 0,"pipSetup", &pxp->pipSetup);
  76.     rc+= DosQueryProcAddr(hmDll, 0,"pipSend",  &pxp->pipSend);
  77.     rc+= DosQueryProcAddr(hmDll, 0,"pipReceive", &pxp->pipReceive);
  78.     rc+= DosQueryProcAddr(hmDll, 0,"pipCleanup", &pxp->pipCleanup);
  79.  
  80.     if (rc!=0) 
  81.         return (PIP_ERROR);
  82.  
  83.     // reset everything
  84.     memset(pxs, 0, sizeof(*pxs));
  85.  
  86.     // load socket
  87.     pxs->hab= hab;
  88.  
  89.     pxs->PipVersion= PIP_VERSION;
  90.     pxs->hmPlugDll= hmDll;
  91.  
  92.     pxs->ioConPutChar= conputc;
  93.     pxs->ioConPutData= conputs;
  94.  
  95.     pxs->ioSerQueryAvail= serquery;
  96.     pxs->ioSerGetChar=    sergetc;
  97.     pxs->ioSerPutChar=    serputc;
  98.     pxs->ioSerUngetData=serungets;
  99.     pxs->ioSerPutData=    serputs;
  100.     pxs->ioSerPutBrk=    sersendbrk;
  101.  
  102.     pxs->dlgErrorMsg=     ErrorMsg;
  103.     pxs->dlgInfoMsg=     InfoMsg;
  104.  
  105.     pxs->dlgHwndFrame=     HWND_DESKTOP;
  106.     pxs->hfComDevice=     0;
  107.     pxs->ulBaud=          0;
  108.  
  109.     pxs->PlugPrivate=    (void*)0;
  110.  
  111.     return (PIP_OK);
  112. }
  113.     
  114.  
  115.  
  116.  
  117.  
  118.  
  119. /***********************************************************************
  120. *    Show an error message                                             *
  121. *                                                                      *
  122. *                                                                      *
  123. ***********************************************************************/
  124. void 
  125. ErrorMsg(char *txt)
  126. {
  127.     WinMessageBox(HWND_DESKTOP, 0, txt, "Error", 
  128.                 0, MB_OK | MB_ERROR | MB_MOVEABLE);
  129. }
  130.  
  131.  
  132. /***********************************************************************
  133. *    Show an error message                                             *
  134. *                                                                      *
  135. *                                                                      *
  136. ***********************************************************************/
  137. void 
  138. InfoMsg(char *txt)
  139. {
  140.     WinMessageBox(HWND_DESKTOP, 0, txt, "Information", 
  141.                 0, MB_OK | MB_INFORMATION | MB_MOVEABLE);
  142. }
  143.  
  144.