--   Offset   Field     Description
--
--    000     ID        ID literal to scan for 'AZSB'
--    004     DRV       Drive Pgm was loaded from (ASCII)
--    005     AUTH      Auth Device (A,B,C=disk)
--    006     PTYPE     Protection Type (C,D,E,I,P)
--    007     PROD      Product Name (ASCIIZ)
--    016     SNP       Product serial number
--    020     HNUC      NUC file handle
--    022     AVERS     Version of Authorization
--    024     ECL       Exec-Count Limit
--    026     DFT       0 = m/d/y, 1 = d/m/y, 2 = y/m/d
--    028     EDL       Expire-Days Limit
--    030     ETL       Elapsed time on last day (etl * 2)secs
--    032     ED        Expire-Date (ASCIIZ)
--    041     CHKSUM    checksum
--    042     NUC       Network-Users current count
--    044     NUL       Network-Users Limit
--    046     ICR       Install counts remaining
--    048     ACCFLG    Access Flags 1-64
--    056     USRDAT    User-Data
--    064     RTYPE     Reg. Type (N,U=Non-Ver, None)
--    065     RNAME     Register name (ASCIIZ)
--    116     RCOMP     Register to company (ASCIIZ)
--    167     RLOC      Register to location (ASCIIZ)
--    218     RDATE     Register Date (ASCIIZ)
--    227     CDATE     Current System Date (ASCIIZ)
--    236     RSRVD1
--    256     SECSTR    Secure-String (expanded ASCIIZ)
--    512     FUNC      function #
--    514     STAT1     pass completion status
--    516     STAT2     pass completion status
--    518     STAT3     pass completion status
--    520     SOURCE    source path (including drive ASCIIZ)
--    583     TARGET    target path (including drive ASCIIZ)
--    646     RSRVD2
--    648     PIN       PIN (SCB Only)
--    652     RUC       reset use count
--    654     PCNT      # programs updated
--    656     RSRVD3
--    658     UNINST    DO Uninstall (0=No/1=Yes)
--    660     REG       NV Reg during install (0=No/1=Yes)
--    662     RSRVD4
--    666     CODE      auth code (ASCIIZ nnnnn-nnnnn-nnnnn)
--    696     RSRVD5
--
to handle buttonClick
	linkDLL "kernel"                  -- need these to build SCB structure
		word    GlobalAlloc(word, dword )
		pointer GlobalLock(word)
		int     GlobalUnlock(word)
		word    GlobalFree(word)
	end 
	linkDLL "evchk3.dll"              --  this is the name of the DLL
		int     evchk3(pointer)
	end
	
	get checkProtection()             -- get protection information
	-- code to handle return value goes here
					
	unlinkDLL "kernel"                                                
	unlinkDLL "evchk.dll"
end

to get checkProtection  
	-- Allocate and Lock SCB in Global Memory
	set hSCB to GlobalAlloc(66, 770)  -- 66 = GMEM_ZEROINIT, 770 = size of SCB
	set pSCB to GlobalLock(hSCB)      -- get pointer to struct
	
	-- initialize fields for EVCHK3 call
	get pointerString(0, pSCB, "AZSB")        -- Signature Literal
	get pointerInt(514, pSCB, -1)             -- Dummy Return Code
	get pointerInt(512, pSCB, 1)              -- Code 0, 1, or 2
	get pointerString(520, pSCB, "C:\PCHECK.EXE") -- Check Drive/path/program
	get pointerdWord(16, pSCB, 0)             -- Check program serial number
   get pointerdWord(648, pSCB, 2660806708)   -- Check PIN
	
	-- Call the DLL to perform the security check
	set compStatus to evchk3(pSCB)
	
	if compStatus = 0
		if pointerInt(514, pSCB) = 0
         request "EVCHK Authorization Check Passed"
		else
			request "EVCHK Authorization Check Error =" && \
		      pointerInt(514, pSCB)&"-"&pointerInt(516, pSCB)&"-"&pointerInt(518, pSCB)
			return pointerInt(514, pSCB)
		end
	else
		request "EVCHK3 reports Completion Code Error =" && compStatus
	end
	return compStatus                                       
end     

