home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / msjv7_4.zip / NETBIOS2.ARJ / WNETBIOS.C < prev    next >
C/C++ Source or Header  |  1992-07-01  |  7KB  |  220 lines

  1. /****************************************************************************
  2.     PROGRAM: WNETBIOS.C
  3.  
  4.     PURPOSE: Exports NCB submitting routines and NCB post processing
  5.              routines
  6.     FUNCTIONS:
  7.                NetBiosPostMessage - Allows PostMessage Style
  8.                                     submission of NCBs and their completion
  9.                LibMain            - Called from Libentry() routine at
  10.                                     DLL initialize time
  11.                WEP                - Dll exit point called by Windows
  12.     History:
  13.                 January, 1992       Ray Patch      Created
  14. ****************************************************************************/
  15.  
  16.  
  17. // Include file
  18. #include <windows.h>
  19. #include "ncb.h"
  20. #include "wnetbios.h"
  21.  
  22. //... Default number of NCB's for DOS LAN Manager.
  23.  
  24. #define DEFAULT_MAX_NCBS 12
  25.  
  26. typedef struct ENTRY
  27. {
  28.     PNCB     pNcb;
  29.     HWND     hWnd;
  30.     unsigned iMessage;
  31. } ENTRY;
  32.  
  33. ENTRY NcbTable[DEFAULT_MAX_NCBS];
  34. WORD  TableEntriesUsed = 0;
  35.  
  36. //... NCB table pointer used in the post routine.
  37.  
  38. ENTRY _far *NcbTablePtr = NcbTable;
  39.  
  40. //... Our private post routine.
  41.  
  42. extern DWORD PrivPostRoutine;
  43.  
  44. // The following function can be used in lieu of
  45. //  PrivPostRoutine
  46.  
  47. extern void  cdecl interrupt far PostRoutine(
  48.                 unsigned int es, unsigned int ds,
  49.                 unsigned int di, unsigned int si,
  50.                 unsigned int bp, unsigned int sp,
  51.                 unsigned int bx, unsigned int dx,
  52.                 unsigned int cx, unsigned int ax,
  53.                 unsigned int ip, unsigned int cs,
  54.                 unsigned int flags);
  55.  
  56.  
  57.  
  58. //===========================================================================
  59. //  FUNCTION: LibMain(HANDLE, WORD, WORD, LPSTR)
  60. //
  61. //  PURPOSE : Is called by LibEntry. LibEntry is called by Windows when
  62. //          the DLL is loaded.
  63. //============================================================================
  64.  
  65. int FAR PASCAL LibMain(hModule, wDataSeg, cbHeapSize, lpszCmdLine)
  66. HANDLE    hModule;
  67. WORD    wDataSeg;
  68. WORD    cbHeapSize;
  69. LPSTR   lpszCmdLine;
  70. {
  71.     register LPBYTE p;
  72.  
  73.     //... zero the entire NCB table.
  74.  
  75.     for(p = (LPBYTE) NcbTable; p != (LPBYTE) &NcbTable[DEFAULT_MAX_NCBS]; ++p)
  76.     {
  77.         *p = 0;
  78.     }
  79.  
  80.     return 1;
  81. }
  82.  
  83. //============================================================================
  84. //  FUNCTION:  WEP(int)
  85. //
  86. //  PURPOSE:  Performs cleanup tasks when the DLL is unloaded.
  87. //============================================================================
  88.  
  89. int FAR PASCAL WEP(int bSystemExit)
  90. {
  91.     return 1;
  92. }
  93.  
  94. //============================================================================
  95. //  FUNCTION:  NetBiosPostMessage()
  96. //
  97. //  PURPOSE:  Posts a message to the parent window when an NCB completes.
  98. //============================================================================
  99.  
  100. int  _far _pascal NetBiosPostMessage(HWND hWnd, unsigned iMessage,
  101.                      WORD wParam, PNCB pNcb)
  102. {
  103.     int err;
  104.  
  105.     //... if the call is asynchronous and the call turned on the NOTIFY_IF_ASYNC
  106.     //... bit the we have to store the information in the table before calling
  107.     //... NetBIOS.
  108.     
  109.     if    ((pNcb->ncb_command & ASYNCH) && (wParam & NOTIFY_IF_ASYNC))
  110.     {
  111.         ENTRY _far *p;
  112.  
  113.         if ( TableEntriesUsed == DEFAULT_MAX_NCBS )
  114.         {
  115.             return -1;      //... Out of table entries (i.e. NCBs).
  116.         }
  117.  
  118.         //... If we are here then we know we have a free
  119.         //... table entry, all we have to do is find it.
  120.  
  121.         for(p = NcbTable; p->pNcb != (PNCB) NULL; p++) ;
  122.  
  123.         //... p = the first free entry in the table. Now we can save the
  124.         //... information in the table and call NetBIOS.
  125.  
  126.         p->pNcb = pNcb;
  127.         p->hWnd = hWnd;
  128.         p->iMessage = iMessage;
  129.  
  130.         //... we need to use our post routine.
  131.  
  132.         pNcb->ncb_post  = (DWORD) PostRoutine;
  133.         /*
  134.          * User's can either use PrivPostRoutine (in post.asm)
  135.          * or PostRoutine (in wnetbios.c) for post routine
  136.          * Both perform the same function although assembly
  137.          * routine is more efficient. In order to use
  138.          * asm routine, use
  139.          *       pNcb->ncb_post = PrivPostRoutine;
  140.          *
  141.          */
  142.  
  143.         if ((err = NetBiosRequest(pNcb)) != (int) 0xFF)
  144.         {
  145.             //... if the asynchronous call completed immediately the we have
  146.             //... to free our table entry and do the PostMessage() call here
  147.             //... since our post routine will get called by NetBIOS.
  148.  
  149.             p->pNcb = 0L;
  150.  
  151.             PostMessage(hWnd, iMessage, pNcb->ncb_command, (DWORD) pNcb);
  152.         }
  153.         else
  154.         {
  155.             ++TableEntriesUsed;
  156.         }
  157.  
  158.         return err;
  159.     }
  160.  
  161.     //... if we are here then we are taking care of a
  162.     //... synchronous call or the call was asynchronous
  163.     //... but the caller does not what a message posted.
  164.  
  165.     err = NetBiosRequest( pNcb);
  166.  
  167.  
  168.     if (wParam & NOTIFY_IF_SYNC)
  169.     {
  170.         PostMessage(hWnd, iMessage, pNcb->ncb_command, (DWORD) pNcb);
  171.     }
  172.  
  173.     return err;
  174. }
  175.  
  176. //============================================================================
  177. //  FUNCTION:  PostRoutine
  178. //
  179. //  PURPOSE:  Post Routine for Asynchronous NCBs. This can be used in lieu
  180. //            of assembly routine to acheive the same result.
  181. //
  182. //  History:
  183. //              January, 1992       Alok Sinha      Created
  184. //============================================================================
  185.  
  186.  
  187. void  cdecl interrupt far  PostRoutine(
  188.                  es,      ds,
  189.                  di,      si,
  190.                  bp,      sp,
  191.                  bx,      dx,
  192.                  cx,      ax,
  193.                  ip,      cs,
  194.                  flags)
  195. unsigned es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags;
  196. {
  197.     PNCB pncb;
  198.     WORD i;
  199.  
  200.     // ES:BX contains pointer to just completed NCB
  201.     pncb = (PNCB) MAKELONG ( bx, es);
  202.  
  203.     // Loop thru Entry table until we find an NCB pointer matching
  204.     // NCB pointer in ES:BX.
  205.     for ( i = 0 ; i < TableEntriesUsed; i++)
  206.         if ( NcbTablePtr[i].pNcb == pncb)
  207.         {
  208.             // Found a match. Remove the entry from table and
  209.             // post a message to the originating window
  210.             TableEntriesUsed--;
  211.             NcbTablePtr[i].pNcb = (PNCB) NULL;
  212.             PostMessage ( NcbTablePtr[i].hWnd,
  213.                           NcbTablePtr[i].iMessage,
  214.                           pncb->ncb_command,
  215.                           (DWORD) pncb
  216.                         );
  217.             break;
  218.         }
  219. }
  220.