{ wymagane: - uses Registry, Windows, SysUtils; - $IFDEF JPKDynLink - ładowanie dynamiczne - konieczne wywołanie InitJPKDLL; } {$IFDEF NOLink} {$UNDEF JPKDynLink} {$UNDEF JPKStatLink} {$ELSE} {$IFNDEF JPKDynLink} {$DEFINE JPKStatLink} {$ENDIF} {$ENDIF} {$IFDEF JPKDynLink} {$IFDEF JPKStatLink} >>Jednocześnie zdefiniowano JPKDynLink i JPKStatLink<< {$ENDIF} {$ENDIF} {$IFNDEF NOTYPESDEF} {$IFDEF UNICODE} type PMainAnsiChar = PAnsiChar; PMainChar = PChar; {$ELSE} type PMainAnsiChar = PChar; PMainChar = PWideChar; NativeUInt = Integer; {$ENDIF} {$ENDIF} type //Typy metod zwrotnych definiowanych po stronie klienta TProgressProc = procedure(SessionID: Pointer; FilesCount, CurrentFile, FileSize, CurrentPosition: Int64; var UserBreak: Boolean; Err: Integer; ErrMsg: PMainChar); stdcall; TFinishProc = procedure(SessionID: Pointer; ReferenceNumber: PMainChar; Status: Integer; StatusText: PMainChar; UPO: PMainChar; UserBreak: Boolean; Err: Integer; ErrMsg: PMainChar); stdcall; //Typy metod DLL TSetLic = procedure(licText:PMainChar); stdcall; TSetPublicKeyFile = procedure(KeyFileName, KeyPass:PMainChar); stdcall; TSetCertFile = procedure(CertFileNameOdIndex,CertPass:PMainChar); stdcall; TGetCertCurrentIndex = function:Integer; stdcall; TShowCertList = function(ParentHandle:NativeUInt):Integer; stdcall; TSetPublicKey = procedure(Key:Pointer; KeySize:Integer; KeyPass:PMainChar); stdcall; TSetCert = procedure(Cert:Pointer; CertSize:Integer; CertPass:PMainChar); stdcall; TSetRaportDir = procedure(Dir:PChar); stdcall; TSetProgressCaption = function(SessionID:Pointer; Caption:PMainChar):Boolean; stdcall; TSetParentwindowHandle = procedure(Handle:NativeUInt); stdcall; TInternetSettingsForm = procedure(ParentHandle:NativeUInt); stdcall; TGetCertyficateCount = function:Integer; stdcall; TGetCertyficate = function(Index:Integer; out cert:PMainChar):Boolean; stdcall; TAddXMLJPK = function(XML:PMainAnsiChar; DocType:Byte; DefFileName:PMainChar=nil):Integer; stdcall; TAddXMLJPKFile = function(XMLFileName:PMainChar; DocType:Byte):Integer; stdcall; {TAddXMLJPKex = function(XML:PMainAnsiChar; DocType:Byte; FormatXML:Boolean):Integer; stdcall; TAddXMLJPKFileEx = function(XMLFileName:PMainChar; DocType:Byte; FormatXML:Boolean):Integer; stdcall;} TSignSendJPK = function(TestMode:Boolean; Progress:TProgressProc; Finish:TFinishProc; SyncFinish:Boolean):Pointer; stdcall; TSignSendJPKAndWait = function(TestMode:Boolean; Progress:TProgressProc; out ReferenceNumbers:PMainChar):Boolean; stdcall; TSignSendBreak = procedure(SessionID:Pointer); stdcall; TWaitForEnd = procedure(SessionID:Pointer; out ReferenceNumbers:PMainChar); stdcall; TGetReferenceNumbers = function(SessionID:Pointer):PMainChar; stdcall; TGetUPO = function(TestMode:Boolean; ReferenceNumber : PMainChar; out UPO : PMainChar; out Status : Integer; out StatusText : PMainChar) : Boolean; stdcall; TBreakGetUPO = function(ReferenceNumber : PMainChar):Boolean; stdcall; TJPKGetLastError = function(out ErrText:PMainChar):Integer; stdcall; TFileNameValidate = function(const FileName:PMainChar; out errText: PMainChar):Boolean; stdcall; TXMLValidate = function(const xmlData: PMainAnsiChar; out errText: PMainChar): Boolean; stdcall; TXMLFileValidate = function(const FileName: PMainChar; out errText: PMainChar): Boolean; stdcall; TXMLValidateBreak = procedure; stdcall; TPrintUPO = function(UPO:PMainChar; ParentHandle:NativeUInt):Integer; stdcall; TPrepareHTMLUPO = function(UPOXML: PAnsiChar; XMLFileName:PChar; out UPOHTML: PChar): Boolean; stdcall; TFinalizeDLL = procedure; stdcall; const JPKLibDLLName = 'JPKLibUI.dll'; {$IFDEF JPKStatLink} //Metody wiązane statycznie procedure SetLic(licText:PMainChar); stdcall; external JPKLibDLLName; procedure SetPublicKeyFile(KeyFileName, KeyPass:PMainChar); stdcall; external JPKLibDLLName; procedure SetCertFile(CertFileNameOdIndex,CertPass:PMainChar); stdcall; external JPKLibDLLName; function GetCertCurrentIndex:Integer; stdcall; external JPKLibDLLName; function ShowCertList(ParentHandle:NativeUInt):Integer; stdcall; external JPKLibDLLName; procedure SetPublicKey(Key:Pointer; KeySize:Integer; KeyPass:PMainChar); stdcall; external JPKLibDLLName; procedure SetCert(Cert:Pointer; CertSize:Integer; CertPass:PMainChar); stdcall; external JPKLibDLLName; procedure SetRaportDir(Dir:PChar); stdcall; external JPKLibDLLName; function SetProgressCaption(SessionID:Pointer; Caption:PMainChar):Boolean; stdcall; external JPKLibDLLName; procedure SetParentwindowHandle(Handle:NativeUInt); stdcall; external JPKLibDLLName; procedure InternetSettingsForm(ParentHandle:NativeUInt); stdcall; external JPKLibDLLName; function GetCertyficateCount:Integer; stdcall; external JPKLibDLLName; function GetCertyficate(Index:Integer; out cert:PMainChar):Boolean; stdcall; external JPKLibDLLName; function AddXMLJPK(XML:PMainAnsiChar; DocType:Byte; DefFileName:PMainChar=nil):Integer; stdcall; external JPKLibDLLName; function AddXMLJPKFile(XMLFileName:PMainChar; DocType:Byte):Integer; stdcall; external JPKLibDLLName; {function AddXMLJPKex(XML:PMainAnsiChar; DocType:Byte; FormatXML:Boolean):Integer; stdcall; external JPKLibDLLName; function AddXMLJPKFileEx(XMLFileName:PMainChar; DocType:Byte; FormatXML:Boolean):Integer; stdcall; external JPKLibDLLName;} function SignSendJPK(TestMode:Boolean; Progress:TProgressProc; Finish:TFinishProc; SyncFinish:Boolean):Pointer; stdcall; external JPKLibDLLName; function SignSendJPKAndWait(TestMode:Boolean; Progress:TProgressProc; out ReferenceNumbers:PMainChar):Boolean; stdcall; external JPKLibDLLName; procedure SignSendBreak(SessionID:Pointer); stdcall; external JPKLibDLLName; procedure WaitForEnd(SessionID:Pointer; out ReferenceNumbers:PMainChar); stdcall; external JPKLibDLLName; function GetReferenceNumbers(SessionID:Pointer):PMainChar; stdcall; external JPKLibDLLName; function GetUPO(TestMode:Boolean; ReferenceNumber : PMainChar; out UPO : PMainChar; out Status : Integer; out StatusText : PMainChar) : Boolean; stdcall; external JPKLibDLLName; function BreakGetUPO(ReferenceNumber : PMainChar):Boolean; stdcall; external JPKLibDLLName; function JPKGetLastError(out ErrText:PMainChar):Integer; stdcall; external JPKLibDLLName; function FileNameValidate(const FileName:PMainChar; out errText: PMainChar):Boolean; stdcall; external JPKLibDLLName; function XMLValidate(const xmlData: PMainAnsiChar; out errText: PMainChar): Boolean; stdcall; external JPKLibDLLName; function XMLFileValidate(const FileName: PMainChar; out errText: PMainChar): Boolean; stdcall; external JPKLibDLLName; procedure XMLValidateBreak; stdcall; external JPKLibDLLName; function PrintUPO(UPO:PMainChar; ParentHandle:NativeUInt):Integer; stdcall; external JPKLibDLLName; function PrepareHTMLUPO(UPOXML: PAnsiChar; XMLFileName:PChar; out UPOHTML: PChar): Boolean; stdcall; external JPKLibDLLName; procedure FinalizeDLL; stdcall; external JPKLibDLLName; {$ENDIF} {$IFDEF JPKDynLink} //Dynamiczne ładowanie biblioteki type JPKLoadLibraryException = class(Exception); JPKGetProcAddressException = class(Exception); const cRegJPK = 'Software\IPSPI\JotPeK'; cRegJPKPathKeyName = 'Path'; var JPKDLLFullPath: String = ''; //Przed wywołanie InitJPKDLL można zdefiniować własną ścieżkę do DLL var SetLic: TSetLic = nil; SetPublicKeyFile: TSetPublicKeyFile = nil; SetCertFile: TSetCertFile = nil; GetCertCurrentIndex: TGetCertCurrentIndex = nil; ShowCertList: TShowCertList = nil; SetPublicKey: TSetPublicKey = nil; SetCert: TSetCert = nil; SetRaportDir: TSetRaportDir = nil; SetProgressCaption: TSetProgressCaption = nil; SetParentwindowHandle: TSetParentwindowHandle = nil; InternetSettingsForm: TInternetSettingsForm = nil; GetCertyficateCount: TGetCertyficateCount = nil; GetCertyficate: TGetCertyficate = nil; AddXMLJPK: TAddXMLJPK = nil; AddXMLJPKFile: TAddXMLJPKFile = nil; {AddXMLJPKex: TAddXMLJPKex = nil; AddXMLJPKFileEx: TAddXMLJPKFileEx = nil;} SignSendJPK: TSignSendJPK = nil; SignSendJPKAndWait: TSignSendJPKAndWait = nil; SignSendBreak: TSignSendBreak = nil; WaitForEnd: TWaitForEnd = nil; GetReferenceNumbers: TGetReferenceNumbers = nil; GetUPO: TGetUPO = nil; BreakGetUPO: TBreakGetUPO = nil; JPKGetLastError: TJPKGetLastError = nil; FileNameValidate: TFileNameValidate = nil; XMLValidate: TXMLValidate = nil; XMLFileValidate: TXMLFileValidate = nil; XMLValidateBreak: TXMLValidateBreak = nil; PrintUPO: TPrintUPO = nil; PrepareHTMLUPO: TPrepareHTMLUPO = nil; FinalizeDLL: TFinalizeDLL = nil; vJPKLib: THandle = 0; procedure FreeJPKDLL; begin if vJPKLib<>0 then FreeLibrary(vJPKLib); vJPKLib:=0; end; procedure InitJPKDLL; var vDLLPath: String; function GetPA(procName:String):TFarProc; begin Result:=GetProcAddress(vJPKLib,PChar(procName)); if Result=nil then begin FreeJPKDLL; raise JPKGetProcAddressException.Create(Format('W bibliotece %s nie znaleziono metody "%s"!',[vDLLPath,procName])); end end; begin if JPKDLLFullPath='' then begin vDLLPath:=ExtractFilePath(ParamStr(0)); With TRegIniFile.Create do begin vDLLPath:=ReadString(cRegJPK,cRegJPKPathKeyName,vDLLPath); Free; end; if Copy(vDLLPath,Length(vDLLPath),1)<>'\' then vDLLPAth:=vDLLPath+'\'; JPKDLLFullPath:=vDLLPath+JPKLibDLLName; end; vJPKLib:=LoadLibrary(PChar(JPKDLLFullPath)); if vJPKLib=0 then JPKLoadLibraryException.Create(Format('Podczas ładowania biblioteki %s wystąpił błąd nr %s.',[JPKDLLFullPath, IntToStr(GetLastError)])); SetLic:=GetPA('SetLic'); SetPublicKeyFile:=GetPA('SetPublicKeyFile'); SetCertFile:=GetPA('SetCertFile'); GetCertCurrentIndex:=GetPA('GetCertCurrentIndex'); ShowCertList:=GetPA('ShowCertList'); SetPublicKey:=GetPA('SetPublicKey'); SetCert:=GetPA('SetCert'); SetRaportDir:=GetPA('SetRaportDir'); SetProgressCaption:=GetPA('SetProgressCaption'); SetParentwindowHandle:=GetPA('SetParentwindowHandle'); InternetSettingsForm:=GetPA('InternetSettingsForm'); GetCertyficateCount:=GetPA('GetCertyficateCount'); GetCertyficate:=GetPA('GetCertyficate'); AddXMLJPK:=GetPA('AddXMLJPK'); AddXMLJPKFile:=GetPA('AddXMLJPKFile'); {AddXMLJPKex:=GetPA('AddXMLJPKex'); AddXMLJPKFileEx:=GetPA('AddXMLJPKFileEx');} SignSendJPK:=GetPA('SignSendJPK'); SignSendJPKAndWait:=GetPA('SignSendJPKAndWait'); SignSendBreak:=GetPA('SignSendBreak'); WaitForEnd:=GetPA('WaitForEnd'); GetReferenceNumbers:=GetPA('GetReferenceNumbers'); GetUPO:=GetPA('GetUPO'); BreakGetUPO:=GetPA('BreakGetUPO'); JPKGetLastError:=GetPA('JPKGetLastError'); FileNameValidate:=GetPA('FileNameValidate'); XMLValidate:=GetPA('XMLValidate'); XMLFileValidate:=GetPA('XMLFileValidate'); XMLValidateBreak:=GetPA('XMLValidateBreak'); PrintUPO:=GetPA('PrintUPO'); PrepareHTMLUPO:=GetPA('PrepareHTMLUPO'); FinalizeDLL:=GetPA('FinalizeDLL'); AddExitProc(FreeJPKDLL); end; {$ENDIF}