SAMPLE: Using NetBIOS Under Microsoft WindowsLast reviewed: February 15, 1996Article ID: Q84071 |
The information in this article applies to:
SUMMARYIn the Microsoft Windows operating system, an application can use NetBIOS functions in every Windows mode (real, standard, or 386 enhanced). However, the application must conform to some rules, which are briefly discussed in the text below. For more information, see the WNBDEMO file in the Software/Data Library or the article by Alok Sinha and Ray Patch titled "An Introduction to Network Programming Using the NetBIOS Interface," page 61, in the March-April 1992 issue of the "Microsoft Systems Journal." WNBDEMO contains sample source code and additional documentation for NetBIOS under Windows. Download WNBDEMO.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
MORE INFORMATIONWindows provides access to NetBIOS through the NetBIOSCall function. This function is equivalent to issuing Interrupt 5Ch under MS-DOS. Although it is legal to call Interrupt 5Ch directly from within Windows, this is not the recommended practice; use NetBIOSCall. An application should call the NetBIOSCall() function from assembly language to ensure that the registers are preserved for the call. The following is a short stub function that can be used to issue NetBIOS calls under Windows:
extrn NETBIOSCALL : FAR extrn DOS3CALL : FAR assume cs: _TEXT _TEXT SEGMENT WORD PUBLIC 'CODE'; WORD FAR PASCAL nbNetBIOS(LPNCB lpNCB)
PUBLIC nbNetBIOSnbNetBIOS proc FAR
push bp ; save bp mov bp, sp ; sp into bp for stack access push es ; save es push bx ; save bx mov es, word ptr [bp + 8] ; put HIWORD into es mov bx, word ptr [bp + 6] ; put LOWORD into bx call NetBIOSCall ; shazam! xor ah, ah mov al, byte ptr es:[bx + 1] ; return the return code pop bx ; restore bx pop es ; restore es mov sp, bp ; restore sp pop bp ; restore bp ret 4 ; return to caller ; fix-up stacknbNetBIOS endp
_TEXT ENDS ENDThis function takes a FAR pointer to an initialized network control block (NCB) and returns the NCB's return code from the NetBIOS driver. Unlike MS-DOS, Windows also has special memory requirements for NCBs and post routines. The general rule of thumb is to fix the NCBs and post routines in memory as much as possible to prevent paging, banking, or other time-consuming operations during the time that the application uses the NCBs and post routines. For post routines, all code and data segments used by the routine must be placed into FIXED segments of a dynamic-link library (DLL). This causes the segments to be page locked, not banked, and to have other attributes appropriate to the mode in which Windows is running. Because the FIXED keyword is ignored for applications, this code must be placed in a DLL. Remember that the post routine may call only the PostMessage(), PostAppMessage(), and NetBIOSCall() functions; it cannot call any other functions in Windows. To call the nbNetBIOS function given above from the post routine, nbNetBIOS must be placed into a FIXED segment of a DLL and the function must be reentrant. NCBs should be allocated such that they are also page locked, not banked, and have other attributes appropriate to the mode in which Windows is running. The easiest way to do this is to use GlobalAlloc() to allocate memory for the NCB either as GMEM_FIXED or to call the GlobalWire() function to move the memory as low as possible in the address space (followed by a call to GlobalPageLock() in 386 enhanced mode). If the memory is allocated from a DLL with the GMEM_FIXED flag, then the memory will also be page locked--this is true only for allocations from DLLs. As stated above, for further information, refer to the WNBDEMO file in the Software/Data Library.
|
Additional reference words: 3.00 3.10 softlib DDKNET
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |