home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 8 / 08.iso / d / d026 / 25.ddi / NET / WNETLOCK.AS_ / WNETLOCK.AS
Encoding:
Text File  |  1991-04-19  |  7.3 KB  |  271 lines

  1. page        60, 132
  2. title        Windows Network Printing Functions
  3. ;===============================================================================
  4. ;        Filename    WNETPRNT.ASM
  5. ;        Copyright    (C) 1989 by Research Machines
  6. ;        Copyright    (C) 1989-1990 Microsoft Corporation
  7. ;===============================================================================
  8. ; REVISIONS:    24/02/1989    Initial version
  9. ;        15/03/1989    Update to spec 0.56
  10. ;                Add WNetOpenJob and WNetCloseJob
  11. ;        16/03/1989    Change to STANDARD procedures (save si, di, ds)
  12. ;        23/03/1989    Change to segment name / file name
  13. ;                Update to spec 0.58
  14. ;        29/03/1989    Change smbPQEOriginatorName to offset
  15. ;        31/03/1989    Added WNetWatchQueue.
  16. ;                Tidied up comments.
  17. ;                Called ERRSetErrorCode.
  18. ;        04/04/1989    Bug fix to WNetWatchQueue
  19. ;                Add WNetUnwatchQueue
  20. ;                Add WNetLockQueueData
  21. ;                Add WNetUnlockQueueData
  22. ;===============================================================================
  23.  
  24.         memM    equ    1        ; Middle memory model
  25.         ?WIN    =    1        ; Windows prolog/epilog
  26.         ?PLM    =    1        ; Pascal calling convention
  27.  
  28.         .xlist
  29. include     cmacros.inc
  30. include     windows.inc
  31. include     smb.inc
  32. include     wnet.inc
  33. include     wnetcaps.inc
  34. include     wnetprnt.inc
  35.         .list
  36.  
  37.         .sall
  38.  
  39.     CBQDATA    equ    3000
  40.  
  41.  
  42. externFP    MSNetFindLocalSession            ; In file MSNET.ASM
  43. externFP    MSNetMakeAssignListEntry        ; In file MSNET.ASM
  44. externFP    MSNetCancelAssignListEntry        ; In file MSNET.ASM
  45. externFP    MSNetCreateHandle            ; In file MSNET.ASM
  46. externFP    MSNetCloseHandle            ; In file MSNET.ASM
  47.  
  48. externFP    UTLMemMove                ; In file UTILS.ASM
  49. externFP    UTLRemoveTrailingSpaces         ; In file UTILS.ASM
  50. externFP    UTLRemoveTrailingColon            ; In file UTILS.ASM
  51.  
  52. externFP    GlobalLock            ; KERNEL things
  53. externFP    GlobalUnlock
  54. externFP    GlobalAlloc
  55. externFP    GlobalFree
  56.  
  57. externNP    GetWholeQueue            ; WNETPRNQ.ASM
  58.  
  59.  
  60.  
  61. ;===============================================================================
  62. ; ============= DATA SEGMENT ===================================================
  63. ;===============================================================================
  64.  
  65. sBegin        DATA
  66.  
  67. globalW     hHeapSpace, 0, 1     ; global handle of the locked data
  68.  
  69. sEnd        DATA
  70.  
  71. ;===============================================================================
  72. ; ============= CODE SEGMENT ===================================================
  73. ;===============================================================================
  74.  
  75. createSeg    _PRNT, PRNTCODE, BYTE, PUBLIC, CODE
  76. sBegin        PRNTCODE
  77.         assumes CS, PRNTCODE
  78.         assumes DS, DATA
  79.  
  80.  
  81. ;===============================================================================
  82. subttl        WNetLockQueueData
  83. page
  84. ;===============================================================================
  85. ;
  86. ; DESCRIPTION .
  87. ; ENTRY .......
  88. ; EXIT ........
  89. ; COMMENTS ....
  90. ;
  91. ;===============================================================================
  92.  
  93. cProc        WNetLockQueueData, <FAR, PUBLIC>, <si, di>
  94.  
  95.         parmD    lpszLocal
  96.         parmD    lpszUser
  97.         parmD    lplpQ
  98.  
  99.         localD     lpqBuffer
  100.  
  101.         localW    nBufferSize                ; Size of user supplied buffer
  102.         localW    nEntriesReturned            ; Entries in the buffer
  103.         localW    nTotalEntries                ; Entries in the queue
  104.  
  105.         localW    nSessionNumber
  106.         localW    nIndex                    ; Index to next queue entry
  107.         localW    nRequiredBufferSize            ; Size needed to hold all of queue
  108.  
  109.         localD    lpFrontBuffer                ; Pointer to space for structures
  110.         localW    nEndBuffer                ; Offset to space for names
  111.         localW    nSizeOriginName             ; Length current name
  112.  
  113.         localB    fBufferOverflow
  114.         localW    nReturnCode
  115.  
  116.         localV    smbPQ, <size smbPrintQEntry>
  117. cBegin
  118.         mov    ( nReturnCode ), WN_SUCCESS        ; Ever optimistic
  119.  
  120. ;---------------------------------------------------------------
  121. ; Check that we aren't already locking a queue
  122. ;---------------------------------------------------------------
  123.  
  124.         cmp    hHeapSpace, 0
  125.         jz    WNLQDDataNotLocked
  126.  
  127.         mov    nReturnCode, WN_ALREADY_LOCKED
  128.         jmp    WNGQExitNow
  129.  
  130. ;---------------------------------------------------------------
  131. ; Initialize stuff, then grab a buffer
  132. ;---------------------------------------------------------------
  133.  
  134. WNLQDDataNotLocked:
  135.         mov    nBufferSize,CBQDATA
  136.         mov    nEndBuffer,CBQDATA
  137.  
  138.         mov    ax,GMEM_MOVEABLE        ; let it wiggle around
  139.         push    ax                ; in case we realloc
  140.         sub    ax,ax
  141.         push    ax
  142.         push    nBufferSize            ; size (as a dword)
  143.         cCall    GlobalAlloc
  144.         or    ax,ax                ; did we get it?
  145.         jnz    WNLQDHaveBuffer
  146.  
  147.         mov    nReturnCode, WN_OUT_OF_MEMORY
  148.         jmp    WNGQExitFree            ; suffering and death
  149.  
  150. WNLQDHaveBuffer:
  151.         mov    hHeapSpace,ax            ; keep the handle
  152.         push    ax
  153.         cCall    GlobalLock            ; lock it
  154.         mov    word ptr lpqBuffer[0],ax    ; save the pointer
  155.         mov    word ptr lpqBuffer[2],dx
  156.  
  157. ;---------------------------------------------------------------
  158. ; lpszDestination is a device name (a printer hopefully).
  159. ; Search down the assign list for the local name. If not found,
  160. ; give up. (who said I was a quitter?).
  161. ;
  162. ; The spec requires display of UNC shares because of the spooler's show
  163. ; other command.  Deal with it later, folks.  Probably call the name in
  164. ; this function and add code below to toss it out later.
  165. ;---------------------------------------------------------------
  166.  
  167. ValidDevice:    Arg    lpszLocal                ;
  168.         cCall    MSNetFindLocalSession            ;
  169.         cmp    ax, NULL                ;
  170.         jne    SessionFound                ;
  171.  
  172.         mov    ( nReturnCode ), WN_BAD_QUEUE        ; Set return code
  173.         jmp    WNGQExitFree                ; Exit with LocalFree
  174.  
  175. SessionFound:
  176.  
  177.  
  178.         Arg    ax            ; session number
  179.         Arg    lpszUser
  180.         Arg    lpqBuffer
  181.  
  182.         lea    bx,nEntriesReturned
  183.         Arg    RegPairSSBX        ; lpnEntriesReturned
  184.  
  185.         cCall    GetWholeQueue
  186.  
  187.         mov    ( nReturnCode ), ax
  188.         or    ax,ax            ; return success?
  189.         jnz    WNGQExitFree
  190.  
  191. ;---------------------------------------------------------------
  192. ; End of entries in queue. Complete the details in the QUEUESTRUCT
  193. ; at the head of the user supplied buffer.
  194. ;---------------------------------------------------------------
  195.  
  196. EndOfList:    les    bx, ( lpqBuffer )
  197.  
  198.         mov    es: [ bx ].pqName, NULL
  199.         mov    es: [ bx ].pqComment, NULL
  200.         mov    es: [ bx ].pqStatus, WNPRQ_ACTIVE
  201.         mov    ax, ( nEntriesReturned )
  202.         mov    es: [ bx ].pqJobCount, ax
  203.         mov    es: [ bx ].pqPrinters, 1
  204.  
  205.         mov    ax,bx
  206.         mov    dx,es
  207.  
  208.         les    bx,lplpQ    ; hand back pointer to locked structure
  209.         mov    es:[bx],ax
  210.         mov    es:[bx+2],dx
  211.  
  212. ;---------------------------------------------------------------
  213. ; We have successfully filled the buffer with print queue entries.
  214. ;---------------------------------------------------------------
  215.  
  216.         jmp    short WNGQExitNow
  217.  
  218.  
  219. ;---------------------------------------------------------------
  220. ; Return to the calling process after freeing heap space.
  221. ;---------------------------------------------------------------
  222.  
  223. WNGQExitFree:    sub    si,si
  224.         xchg    si,hHeapSpace
  225.         push    si
  226.         cCall    GlobalUnlock
  227.         push    si
  228.         cCall    GlobalFree
  229.  
  230. ;---------------------------------------------------------------
  231. ; Return to the calling process without freeing heap space.
  232. ;---------------------------------------------------------------
  233.  
  234. WNGQExitNow:
  235.         mov    ax,nReturnCode
  236.  
  237. cEnd
  238.  
  239.  
  240. ;========================================================================
  241. ;
  242. ;   WNetUnlockQueueData
  243. ;
  244. ;
  245.  
  246. cProc WNetUnlockQueueData, <FAR, PUBLIC>, <SI>
  247.  
  248.     parmD   lpsz
  249.  
  250. cBegin
  251.     mov    ax, WN_ALREADY_LOCKED
  252.  
  253.     mov    si,hHeapSpace
  254.  
  255.     or    si,si
  256.     jz    wnuqd_exit
  257.  
  258.     cCall    GlobalUnlock, <si>
  259.     cCall    GlobalFree, <si>
  260.  
  261.     sub    ax,ax
  262.  
  263.     mov    hHeapSpace, ax
  264.  
  265. wnuqd_exit:
  266. cEnd
  267.  
  268. sEnd        PRNTCODE
  269.  
  270.         end
  271.