Hello. I no longer know how to get rid of this error ...
Error periodically comes out in the second step
Step2 Accesse violation at address 0AC95985 in module ... Read of address FFFFFFFC, high (a) = 31
Library hash_sha256; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses System.SysUtils, System.Classes, System.Hash, Vcl.Dialogs; {$R *.res} function MyHash(AKey, AData: PAnsiChar): Pchar; stdcall; var a: TArray<byte>; i: integer; s: ShortString; begin try s:=''; Result:=''; try a:=THashSHA2.GetHMACAsBytes(String(AData), String(AKey)); except on E : Exception do ShowMessage('Step1'+E.Message); end; try for i:=0 to high(a) do s:=s+PChar(inttohex(a[i],2)); except on E : Exception do ShowMessage('Step2 '+E.Message+', high(a)='+IntToStr(high(a))); end; try Result:=Pchar(s+''); except on E : Exception do ShowMessage('Step3'+E.Message); end; except on E : Exception do begin Result:=Pchar(AnsiString(E.Message)); end; end; end; exports MyHash name 'hash_sha256'; begin end. The nuance is that the library is written on 10 delphi (delphi XE 10), and the program that uses it is written on the old Delphi7 ... Apparently, therefore, the AnsiString variant with BORLNDMM.DLL and ShareMem led constantly to Accesse violation but only when connected to the library.
for i:=1 to Length(a). For 100% compatibility, you must specify PAnsiChar everywhere, not PChar. - kami