!  FortranDemo.f90 
!
!  FUNCTIONS:
!  FortranDemo - Entry point of console application.
!

!****************************************************************************
!
!  PROGRAM: FortranDemo
!
!  PURPOSE:  Entry point for the console application.
!
!****************************************************************************

    program FortranDemo

    Use Kernel32

    
         Implicit None 
         
         Interface
            
            SUBROUTINE GetDiskSerialNumber1(drive,  pout,  poutsize,PNPDeviceID)
               !DEC$ ATTRIBUTES STDCALL :: GetDiskSerialNumber1
			   !DEC$ ATTRIBUTES Alias:'GetDiskSerialNumber1':: GetDiskSerialNumber1
               !DEC$ ATTRIBUTES REFERENCE:: pout,  poutsize
               INTEGER :: poutsize
              CHARACTER(len=1) :: drive
              CHARACTER :: pout(*)
              logical :: PNPDeviceID
            End SUBROUTINE
            SUBROUTINE DoReg(user,userlen,regid,regidlen)
               !DEC$ ATTRIBUTES STDCALL :: DoReg
			   !DEC$ ATTRIBUTES Alias:'DoReg':: DoReg
               !DEC$ ATTRIBUTES REFERENCE:: pout,  poutsize
               INTEGER :: userlen,regidlen              
              CHARACTER :: user(*),regid(*)
            End SUBROUTINE
            SUBROUTINE Init()
               !DEC$ ATTRIBUTES STDCALL :: Init
			   !DEC$ ATTRIBUTES Alias:'Init':: Init
              
            End SUBROUTINE
            logical function RunAsAdmin()
               !DEC$ ATTRIBUTES STDCALL :: RunAsAdmin
			   !DEC$ ATTRIBUTES Alias:'RunAsAdmin':: RunAsAdmin
              
            End function
         End Interface
          
         CHARACTER(len=20)  dllname
         Logical RetLog
         logical r
         INTEGER poutsize
         CHARACTER  drive
         CHARACTER :: pout(100)
         CHARACTER(len=100) :: user
         CHARACTER(len=300) :: regid
         INTEGER userlen,regidlen
         Pointer (fGetDiskSerialNumber1, GetDiskSerialNumber1)
         Pointer (fDoReg, DoReg)
         Pointer (fInit, Init)
         Pointer (fRunAsAdmin, RunAsAdmin)
          !32位下INTEGER(4)，64位下INTEGER(8)
         !INTEGER(4) hLib
         !DEC$ IF DEFINED (_X86_)            
            INTEGER(4) hLib
            dllname="jydisk.dll"C
            print *,'win32'
         !DEC$ ELSE             
             INTEGER(8) hLib
             dllname="jydisk64.dll"C
             print *,'win64 '
         !DEC$ ENDIF         
         
         hLib = LoadLibrary(dllname)
         print *,'hLib= ',hLib

         fDoReg = GetProcAddress(hLib, 'DoReg'C)
		 print *,'DoReg= ',fDoReg
         
         fInit = GetProcAddress(hLib, 'Init'C)
		 print *,'Init= ',fInit
         
         fRunAsAdmin = GetProcAddress(hLib, 'RunAsAdmin'C)
		 print *,'RunAsAdmin= ',fRunAsAdmin
         
         fGetDiskSerialNumber1 = GetProcAddress(hLib, 'GetDiskSerialNumber1'C)         
		 print *,'GetDiskSerialNumber1= ',fGetDiskSerialNumber1
		 
         call Init()
          
         r=RunAsAdmin()
         if (r) then 
           print *,'管理员=是'
         else
          print *,'管理员=否'
         endif
         user="171833017@qq.com"
         regid="telme"
         userlen=len(trim(user))
         regidlen=len(trim(regid))
         call DoReg(user,userlen, regid,regidlen)
         
         drive="c"
         PRINT *, '盘符= ',drive
         call GetDiskSerialNumber1(drive, pout,poutsize,false)
		 !print *,'RetLog= ',Retlog

		 PRINT *, '序列号位数= ',poutsize
         PRINT *, '序列号= ',pout

         RetLog = FreeLibrary(hLib)

         pause
    end program FortranDemo

