! Dic32U.dll function declaration
INTERFACE


!(0).Search for dongle device(s) connected to the computer
INTEGER*4 FUNCTION DIC_Find()
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_Find@0' :: DIC_Find
END FUNCTION DIC_Find
! Return value:
! it is < 0, indicating an error code is returned, for details, please see below.
! If it is = 0, no card reader device exists
! If it is >0, the return value is the number of card reader device(s) 
!(Note: Normally, even if the user does not connect any device, the driver program will report the card presence 
!due to the existence of the driver. It is necessary to confirm the real device presence with command DIC_Open.) 
!Suppose that maximum 32 card reader devices can be connected to a computer. 
! ====================================================================

!(1).Find a dongle that has specific management code 
INTEGER*4 FUNCTION DIC_FindByMgrCode(pMgrCode)
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_FindByMgrCode@4' :: DIC_FindByMgrCode
INTEGER*4 pMgrCode !Managment code
END FUNCTION DIC_FindByMgrCode
// Input:
// pMgrCode	a pointer to DICST_ManagerCode structure
// 
// Return:
// The same as DIC_Find
====================================================================

!(2).Open the specified card reader
INTEGER*4 FUNCTION DIC_Open(hic,reader_name)
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_Open@8' :: DIC_Open
INTEGER*4 hic
INTEGER*4 reader_name
END FUNCTION DIC_Open
// Input:
// hic	Card handle,it's a integer value.
// (1)positive value, it is a enumeration value，any one of 0, 1, 2, ... return value of DIC_Find(). If reader_name 
//     is not null, card reader name is returned.
// (2)negative value，reader_name parameter can not be null，DIC_Open will attempt to open the card reader directly 
//     by the device name in reader_name; in case of a virtual device, it is the path directory of the file to be opened. 

// reader_name  name of card reader.
// An input/output parameter, see comments on hic

// Return value:
// >=0				Success, the opened handle is returned
// <0				An error code is returned, for detailed descriptions, please refer to code defined below.
//====================================================================

!(3).Close the specified card reader
INTEGER*4 FUNCTION DIC_Close (hic)
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_Close@4' :: DIC_Close
INTEGER*4 hic
END FUNCTION DIC_Close
// Input:
// hic: Card handle, must be consistent with the hic returned by DIC_Open. 
// Return:
// An error code , for detailed descriptions, please refer to code defined below.
! ====================================================================

!(4). Create virtual IC card file(*virtual card private instruction)
INTEGER*4 FUNCTION DIC_Create(filename, mfname, atr, atrlen)
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_Create@14' :: DIC_Create
INTEGER*4 filename
INTEGER*4 mfname
INTEGER*4 atr
INTEGER*2 atrlen
END FUNCTION DIC_Create
// Input:
// filename:	Path file name to be created 
// mfname:		Main volume name
// atr:			Software developer information 
// atrlen:		Software developer information length

// Return :
// An error code , for detailed descriptions, please refer to code defined below.
! ======================================================================

! (5). Get the dynamic library version
INTEGER*4 FUNCTION DIC_GetVersion(ver)
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_GetVersion@4' :: DIC_GetVersion
INTEGER*4 ver
END FUNCTION DIC_GetVersion
// Input:
// ver: returns the version number of the dynamic library, the version content is:
//    [V/R]xx.yy
// For example, R01.10 means it is "Real card dynamic library Version 1.10 "
//              R03.02 indicats "Virtual card dynamic library Version 3.02 "

// Return:
//	An error code , for detailed descriptions, please refer to code defined below.
! ======================================================================

! (6). Complete operations on the specified device 
INTEGER*4 FUNCTION DIC_Command (hic, cmd, cmddata)
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_Command@12' :: DIC_Command
INTEGER*4 hic
INTEGER*4 cmd
INTEGER*4 cmddata
END FUNCTION DIC_Command
// Input
// hic		Device handle 
// cmd		Specific operation, different constants represent different operations, for details, see below.
// cmddata	Input/output data related to the command，see comments on below.
!========================================================================

! 7.  Get data from return value of DIC_Cmd
INTEGER*4 FUNCTION DIC_Get (xdata, p1, p2, buffer)
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_Get@16' :: DIC_Get
INTEGER*4 xdata
INTEGER*4 p1
INTEGER*4 p2
INTEGER*4 buffer
END FUNCTION DIC_Get
// Input:
// xdata	Source data buffer
// p1		Mode/shift, if the highest bit is 1，it is a mode operation，otherwise, it is a user defined shift value
// p2		Return mode / size, the highest 2 bits represent return mode, others indicate the operation size
// buffer	Character type buffer where the data is got
! ====================================================================

! 8. Set data for DIC_Cmd
INTEGER*4 FUNCTION DIC_Set (xdata, p1, p2, p3, buffer)
!DEC$ATTRIBUTES STDCALL, ALIAS : '_DIC_Set@20' :: DIC_Set
INTEGER*4 xdata
INTEGER*4 p1
INTEGER*4 p2
INTEGER*4 p3
INTEGER*4 buffer
END FUNCTION DIC_Set
// Input:
// xdata	Targeted buffer
// p1		Mode/shift, if the highest bit is 1, it is a mode operation，otherwise, it is user defined shift value
// p2		Transfer mode/ size, the highest 2 bits specify the transfer mode, others indicate the operation size
// p3		Normally the value that the user needs to store
// buffer	Character type buffer of the source data, it can be NULL
! ====================================================================

END INTERFACE

! Command defination
integer*4 ,parameter  :: GET_CARD_INFO				=#02000000  
integer*4 ,parameter  :: GET_HARDWARE_INFO			= #00FF1C00 
integer*4 ,parameter  :: GET_MANAGER_CODE			= #00FF1A00 
integer*4 ,parameter  :: GET_CARD_PRIVILEGE			= #00FF2200 
integer*4 ,parameter  :: GET_REMOTE_INFO			= #00FF1e00 
integer*4 ,parameter  :: SET_REMOTE_INFO			= #00FF1003 
integer*4 ,parameter  :: CHECK_REMOTE_INFO			= #01FF1003 
integer*4 ,parameter  :: GET_CURRENT_DIR			= #00001800 
integer*4 ,parameter  :: SET_CURRENT_DIR			= #0000a400 
integer*4 ,parameter  :: GET_CURRENT_FILE			= #00001801 
integer*4 ,parameter  :: SET_CURRENT_FILE			= #0100a400 
integer*4 ,parameter  :: GET_PARENT_DIR				= #00001802 
integer*4 ,parameter  :: SET_PARENT_DIR				= #0000a402 
integer*4 ,parameter  :: LIST_DIR				= #0000b200 
integer*4 ,parameter  ::	READ_FILE			= #0000b000 
integer*4 ,parameter  :: WRITE_FILE				= #0000d000 
integer*4 ,parameter  :: FORMAT_CARD				= #0000e000 
integer*4 ,parameter  :: CREATE_DIR				= #0000e001 
integer*4, parameter  :: CREATE_FILE				= #0100e001 != #0100e000+1 
integer*4 ,parameter  :: REMOVE_DIR				= #0000ee00 
integer*4 ,parameter  :: REMOVE_FILE				= #0000ee01 
integer*4 ,parameter  :: RANDOM					= #00008400 
integer*4 ,parameter  :: RUN					= #03000000 
integer*4 ,parameter  :: CRYPTOTEXT_FILE			= #04000000 
integer*4 ,parameter  :: PLAINTEXT_FILE				= #05000000 

integer*4 ,parameter  :: CHECK_SUPER_PASS			= #00FF1002 
integer*4 ,parameter  :: SET_SUPER_PASS				= #00FFF402 
integer*4 ,parameter  :: GET_UPGRADE_REMOTE_PASS		= #00FF2000 

integer*4 ,parameter  :: DESENC					= #00005000
integer*4 ,parameter  :: DESDEC					= #00005100
integer*4 ,parameter  :: RSAGENKEY				= #00003300
integer*4 ,parameter  :: RSAENC					= #00003400
integer*4 ,parameter  :: RSADEC					= #00003500

integer*4 ,parameter  :: GETFREESPACE				= #00003000
integer*4 ,parameter  :: MODULE_GETFILEFLAG			= #00003600
integer*4 ,parameter  :: MODULE_CRYPTOTEXT_MODFLAG		= #00003700
integer*4 ,parameter  :: MODULE_PLAINTEXT_MODFLAG		= #00003800
integer*4 ,parameter  :: MODULE_ENCRYPT_CONTENT			= #00003900

integer*4 ,parameter  :: SETCOUNTER				= #00005700
integer*4 ,parameter  :: STEPCOUNTER				= #00005800

! 用位来表示当前密码验证的状态
integer*4 ,parameter  :: DICPR_NOPASS		  =0 
integer*4 ,parameter  ::	DICPR_SUPERPASS	  =	4 
integer*4 ,parameter  ::	DICPR_REMOTEPASS  =	8 

! 文件的属性定义
integer*4 ,parameter  :: FILEATTR_NORMAL		= #00 
integer*4 ,parameter  :: FILEATTR_EXEC			= #10 	! 表示可执行
integer*4 ,parameter  :: FILEATTR_DIR			= #20 	! 表示为目录文件
integer*4 ,parameter  :: FILEATTR_UPIGNORE		= #40 	! 表示如果当前安全级别已经高于可执行程序自身的级别，则不执行本程序
integer*4 ,parameter  :: FILEATTR_INTERNAL		= #80 	! 表示为内部应用程序自己使用的文件，不能从外部进行操作
                                        ! 如果一个可执行文件也设置内部属性,在列目录时就只有通过超级密码验证之后才能显示出来
! 注意: LIST_DIR 命令返回的结构既可能是 DICST_Dir 也可能是 DICST_File
! 具体是哪个，要通过判断 FILEATTR_DIR 来决定

! ====================================================================
! 对于 DIC_Get, DIC_Set 的 p1 参数，我们预定义了一些模式操作
! 这些模式操作的最高位我们都设定为 1
integer*4 ,parameter  :: FILL					= #80000000 
integer*4 ,parameter  :: ATR					= #80010000 
integer*4 ,parameter  :: VOLUME					= #80020000 
integer*4 ,parameter  :: FACTORY_TIME				= #80030000 
integer*4 ,parameter  :: HARD_SERIAL				= #80040000 
integer*4 ,parameter  :: SHIP_TIME				= #80050000 
integer*4 ,parameter  :: COS_VERSION				= #80060000 
integer*4 ,parameter  :: ZONE					= #80070000 
integer*4 ,parameter  :: AGENT					= #80080000 
integer*4 ,parameter  :: USER1					= #80090000 
integer*4 ,parameter  :: USER2					= #800A0000 
integer*4 ,parameter  :: DIR_ID					= #800B0000 
integer*4 ,parameter  :: DIR_CLASS				= #800C0000 
integer*4 ,parameter  :: DIR_ATTRIBUTE				= #800D0000 
integer*4 ,parameter  :: DIR_PRIVILEGE				= #800E0000 
integer*4 ,parameter  :: FILE_NO				= #800F0000 
integer*4 ,parameter  :: DIR_NAME				= #80100000 
integer*4 ,parameter  :: FILE_ID				= #80110000 
integer*4 ,parameter  :: FILE_CLASS				= #80120000 
integer*4 ,parameter  :: FILE_ATTRIBUTE				= #80130000 
integer*4 ,parameter  :: FILE_PRIVILEGE				= #80140000 
integer*4 ,parameter  :: FILE_SIZE				= #80150000 
integer*4 ,parameter  :: FILE_NAME				= #80160000 
integer*4 ,parameter  :: WRITE_DATA				= #80170000 
integer*4 ,parameter  :: READ_DATA				= #80180000 
integer*4 ,parameter  :: RUN_DATA				= #80190000 
integer*4 ,parameter  :: RANDOM_SIZE				= #801A0000 
integer*4 ,parameter  :: REMOTE_TAG				= #801B0000 
integer*4 ,parameter  :: REMOTE_PASS				= #801C0000 
integer*4 ,parameter  :: UPGRADE_HARD_SERIAL			= #801D0000 
integer*4 ,parameter  :: UPGRADE_REMOTE_TAG			= #801E0000 
integer*4 ,parameter  :: UPGRADE_REMOTE_PASS			= #801F0000 
integer*4 ,parameter  :: REMOTEPASS_STATUS			= #80200000 
integer*4 ,parameter  :: SUPERPASS_STATUS			= #80210000 
integer*4 ,parameter  :: SUPERPASS_DATA				= #80220000 
integer*4 ,parameter  :: FILE_DATA				= #80230000 

!DICST_Des_Data			!Used by DIC_Set
integer*4 ,parameter  :: DES_KEYFILEID				= #80240000
integer*4 ,parameter  :: DES_KEYINDEX				= #80250000
integer*4 ,parameter  :: DES_DATA				= #80260000

!DICST_After_EncDec_Data	!Used by DIC_Get
integer*4 ,parameter  :: AFTER_ENCDEC_DATA			= #80270000

!DICST_Rsa_Data			!Used by DIC_Set
integer*4 ,parameter  :: RSA_KEYFILEID				= #80280000
integer*4 ,parameter  :: RSA_DATA				= #80290000

!DICST_Rsa_GenKey			!Used by Dic_Set
integer*4 ,parameter  :: RSA_PUBKEYID			= #802A0000
integer*4 ,parameter  :: RSA_PUBKEYSIZE			= #802B0000
integer*4 ,parameter  :: RSA_PIVKEYID			= #802C0000
! ====================================================================
//For the p2 parameter of DIC_Get and DIC_Set, the highest 2 bits indicate data transfer or return mode, 
//the default value of the lower 30-bit is 0, if not, it refers to the operation byte number. 
integer*4 ,parameter  :: BY_VALUE				= #00000000 
integer*4 ,parameter  :: BY_DOUBLE				= #40000000 
integer*4 ,parameter  :: BY_ARRAY				= #80000000 
integer*4 ,parameter  :: BY_STRING				= #C0000000 

// for  DIC_GetData
// BY_VALUE		returned in return value
// BY_DOUBLE		returned in double in string format, such as "328.002"
// BY_ARRAY		returned in pstr 
// BY_STRING		returned in pstr 

// for  DIC_SetData
// BY_VALUE		set data via p3 
// BY_DOUBLE		set double data in string format, such as "328.002"
// BY_ARRAY		set data via pstr 
// BY_STRING		set data via pstr 
! ====================================================================


// Error code ===========================================================


! Success
integer*4 ,parameter  :: SCARD_S_SUCCESS 			= #00000000 

! Internal link check failure
integer*4 ,parameter  :: SCARD_F_INTERNAL_ERROR			= #80100001 

! Operation is terminated by user
integer*4 ,parameter  :: SCARD_E_CANCELLED			= #80100002 

! Incorrect operation handle
integer*4 ,parameter  :: SCARD_E_INVALID_HANDLE			= #80100003 

! Incorrect parameter 
integer*4 ,parameter  :: SCARD_E_INVALID_PARAMETER		= #80100004 

! Registered startup information lost or invalid 
integer*4 ,parameter  :: SCARD_E_INVALID_TARGET			= #80100005 

! Memory not enough for command completion
integer*4 ,parameter  :: SCARD_E_NO_MEMORY			= #80100006 

! Internal overtime
integer*4 ,parameter  :: SCARD_F_WAITED_TOO_LONG		= #80100007 

! User specified buffer is too small, not enough for the return dataUser specified buffer is too small, not enough for the return data
integer*4 ,parameter  :: SCARD_E_INSUFFICIENT_BUFFER		= #80100008 

! Unknown card reader
integer*4 ,parameter  :: SCARD_E_UNKNOWN_READER			= #80100009 

! Over user specified time
integer*4 ,parameter  :: SCARD_E_TIMEOUT			= #8010000A 

! Card occupied by other connection
integer*4 ,parameter  :: SCARD_E_SHARING_VIOLATION		= #8010000B 

! No card in the card reader
integer*4 ,parameter  :: SCARD_E_NO_SMARTCARD			= #8010000C 

! Unknown card type
integer*4 ,parameter  :: SCARD_E_UNKNOWN_CARD			= #8010000D 

! Card reader can not complete card eject operation
integer*4 ,parameter  :: SCARD_E_CANT_DISPOSE			= #8010000E 

! Current card does not support user specified communication protocol
integer*4 ,parameter  :: SCARD_E_PROTO_MISMATCH			= #8010000F 

! Card is not ready for receiving commands
integer*4 ,parameter  :: SCARD_E_NOT_READY			= #80100010 

! Some variable values are not suitable
integer*4 ,parameter  :: SCARD_E_INVALID_VALUE			= #80100011 

! Operation is terminated by system, it may be necessary to log on again or shut down. 
integer*4 ,parameter  :: SCARD_E_SYSTEM_CANCELLED		= #80100012 

! Internal communication error
integer*4 ,parameter  :: SCARD_F_COMM_ERROR			= #80100013 

! Unknown internal error
integer*4 ,parameter  :: SCARD_F_UNKNOWN_ERROR			= #80100014 

! Invalid vendor information
integer*4 ,parameter  :: SCARD_E_INVALID_ATR			= #80100015 

! User attempts to terminate some process not available
integer*4 ,parameter  :: SCARD_E_NOT_TRANSACTED			= #80100016 

! The specifiied card reader is not ready
integer*4 ,parameter  :: SCARD_E_READER_UNAVAILABLE		= #80100017 

! Operation is terminated, service program is allowed to exit
integer*4 ,parameter  :: SCARD_P_SHUTDOWN			= #80100018 

! PCI receiving buffer is too small
integer*4 ,parameter  :: SCARD_E_PCI_TOO_SMALL			= #80100019 

! Card reader drive does not support the current card reader
integer*4 ,parameter  :: SCARD_E_READER_UNSUPPORTED		= #8010001A 

! Card reader driver program can not create an exclusive name, card reader with the same name already exists
integer*4 ,parameter  :: SCARD_E_DUPLICATE_READER		= #8010001B 

! Card is not supported by the current card reader
integer*4 ,parameter  :: SCARD_E_CARD_UNSUPPORTED		= #8010001C 

! Smart card service is not enabled
integer*4 ,parameter  :: SCARD_E_NO_SERVICE			= #8010001D 

! Smart card service is disabled
integer*4 ,parameter  :: SCARD_E_SERVICE_STOPPED		= #8010001E 

! Some unexpected smart card error
integer*4 ,parameter  :: SCARD_E_UNEXPECTED			= #8010001F 

! Smart card software developer information not accessible
integer*4 ,parameter  :: SCARD_E_ICC_INSTALLATION		= #80100020 

! Smart card vendor information not accessible
integer*4 ,parameter  :: SCARD_E_ICC_CREATEORDER		= #80100021 

! Current smart card does not support the function user demanded
integer*4 ,parameter  :: SCARD_E_UNSUPPORTED_FEATURE		= #80100022 

! The specified directory does not exist
integer*4 ,parameter  :: SCARD_E_DIR_NOT_FOUND			= #80100023 

! The specified file does not exist
integer*4 ,parameter  :: SCARD_E_FILE_NOT_FOUND			= #80100024 

! The specified directory is no longer a valid directory
integer*4 ,parameter  :: SCARD_E_NO_DIR				= #80100025 

! The specified file is no longer a valid file, no file selected
integer*4 ,parameter  :: SCARD_E_NO_FILE			= #80100026 

! The file denies any access
integer*4 ,parameter  :: SCARD_E_NO_ACCESS			= #80100027 

! Card is full, no more data write
integer*4 ,parameter  :: SCARD_E_WRITE_TOO_MANY			= #80100028 

! File pointer error
integer*4 ,parameter  :: SCARD_E_BAD_SEEK			= #80100029 

! PIN code error
integer*4 ,parameter  :: SCARD_E_INVALID_CHV			= #8010002A 

! An unrecognized error code is returned from smart card service
integer*4 ,parameter  :: SCARD_E_UNKNOWN_RES_MNG		= #8010002B 

! The certificate requested does not exist
integer*4 ,parameter  :: SCARD_E_NO_SUCH_CERTIFICATE		= #8010002C 

! The certificate requested is not available
integer*4 ,parameter  :: SCARD_E_CERTIFICATE_UNAVAILABLE	= #8010002D 

! No card reader found
integer*4 ,parameter  :: SCARD_E_NO_READERS_AVAILABLE	= #8010002E 

! Data loss during smart card communication, please try again
integer*4 ,parameter  :: SCARD_E_COMM_DATA_LOST			= #8010002F 

! The key file requested does not exist
integer*4 ,parameter  :: SCARD_E_NO_KEY_CONTAINER		= #80100030 

! Card reader can not communicate with the card due to software developer information conflict
integer*4 ,parameter  :: SCARD_W_UNSUPPORTED_CARD		= #80100065 

! Card does not respond to reset
integer*4 ,parameter  :: SCARD_W_UNRESPONSIVE_CARD		= #80100066 

! Card no power
integer*4 ,parameter  :: SCARD_W_UNPOWERED_CARD			= #80100067 

! Card is reset, shared information is invalid
integer*4 ,parameter  :: SCARD_W_RESET_CARD			= #80100068 

! Card is removed
integer*4 ,parameter  :: SCARD_W_REMOVED_CARD			= #80100069 

! Access is denied due to security rules
integer*4 ,parameter  :: SCARD_W_SECURITY_VIOLATION		= #8010006A 

! PIN code is not verified, access is denied
integer*4 ,parameter  :: SCARD_W_WRONG_CHV			= #8010006B 

! Max. PIN code retry number is reached, access is denied
integer*4 ,parameter  :: SCARD_W_CHV_BLOCKED			= #8010006C 

! The last smart card file is reached, no more file available
integer*4 ,parameter  :: SCARD_W_EOF				= #8010006D 

! Operation is terminated by user
integer*4 ,parameter  :: SCARD_W_CANCELLED_BY_USER		= #8010006E 

! Smart card PIN is not set
integer*4 ,parameter  :: SCARD_W_CARD_NOT_AUTHENTICATED		= #8010006F 




! Extended error code  =========================================================

! File already exists
integer*4 ,parameter  :: SCARD_E_FILE_EXISTS			= #A0100001 

! Card-resident memory operation error
integer*4 ,parameter  :: SCARD_E_EPROM_ERROR			= #A0100002 

! User specified CLA is invalid
integer*4 ,parameter  :: SCARD_E_INVALID_CLA			= #A0100003 

! User specified INS is invalid
integer*4 ,parameter  :: SCARD_E_INVALID_INS			= #A0100004 

! Virtual machine address out ranged/abnormal 
integer*4 ,parameter  :: SCARD_E_VM_ADDRESS_ERROR		= #A0100005 

! 0 division error
integer*4 ,parameter  :: SCARD_E_ZERO_DIVIDE			= #A0100006 

! Card is not inserted to the proper place
integer*4 ,parameter  :: SCARD_E_WRONG_POSITION			= #A0100007 

! Card is in an unknown status
integer*4 ,parameter  :: SCARD_E_UNKNOWN_STATE			= #A0100008 

! Card is not opened
integer*4 ,parameter  :: SCARD_E_CARD_NOT_OPENED		= #A0100009 

! Unknown command
integer*4 ,parameter  :: SCARD_E_UNKNOWN_COMMAND		= #A010000A 

! Super password reset number is 0
integer*4 ,parameter  :: SCARD_E_ZERO_TRYTIME			= #A010000B 

! Too many devices are opened
integer*4 ,parameter  :: SCARD_E_TOO_MANY_DEVICE	 	= #A010000C 

! Invalid instruction.
integer*4 ,parameter  ::	SCARD_E_INVALID_INSTRUCTION	= #A010000D 

! card still have more data to return
integer*4 ,parameter  :: SCARD_W_RESPONSE			= #A01000FF 


! Error codes exclusive for virtual devices=================================================

! Virtual card file creation failure
integer*4 ,parameter  :: SCARD_E_FILE_CREATE_FAILED		= #A0101001 

! Virtual card file open failure
integer*4 ,parameter  :: SCARD_E_FILE_OPEN_FAILED		= #A0101002 