Hi all...
Let me preface this with "I have an acceptable work-around"...
I am linking to CryptLib in a rather complex program that is throwing a mysterious run-time error on exit. After much stripping down, here is the MOST simple code that will throw the error:
program Test;
function cryptInit: Integer; stdcall; external 'CL64.DLL';
function cryptEnd: Integer; stdcall; external 'CL64.DLL';
begin
if cryptInit = 0 then
Writeln('Init!');
cryptEnd;
Writeln('Complete');
end.
This code runs fine in Windows 10 but throws the error on Windows 2012 Server R2.
Notes:
- Compiled on FPC 3.04 and on FPC 3.2.2, as I read on this forum 3.0.4 has a bug that can cause this
- Error only on that one OS. SAME code and SAME DLL work in Windows 10
- Works fine in 2012 when compiled in 32-bit mode
Question to the forum: Am I missing any obvious compiler options that would help debug this? I've tried {$S+} and {$INLINE OFF}
=library-loaded,id="C:\\Windows\\SYSTEM32\\cryptbase.dll",target-name="C:\\Windows\\SYSTEM32\\cryptbase.dll",host-name="C:\\Windows\\SYSTEM32\\cryptbase.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\SYSTEM32\\bcryptprimitives.dll",target-name="C:\\Windows\\SYSTEM32\\bcryptprimitives.dll",host-name="C:\\Windows\\SYSTEM32\\bcryptprimitives.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\SYSTEM32\\cryptsp.dll",target-name="C:\\Windows\\SYSTEM32\\cryptsp.dll",host-name="C:\\Windows\\SYSTEM32\\cryptsp.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\system32\\shell32.dll",target-name="C:\\Windows\\system32\\shell32.dll",host-name="C:\\Windows\\system32\\shell32.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\system32\\shlwapi.dll",target-name="C:\\Windows\\system32\\shlwapi.dll",host-name="C:\\Windows\\system32\\shlwapi.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\SYSTEM32\\SHCore.dll",target-name="C:\\Windows\\SYSTEM32\\SHCore.dll",host-name="C:\\Windows\\SYSTEM32\\SHCore.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\SYSTEM32\\profapi.dll",target-name="C:\\Windows\\SYSTEM32\\profapi.dll",host-name="C:\\Windows\\SYSTEM32\\profapi.dll",symbols-loaded="0",thread-group="i1"
=thread-created,id="2",group-id="i1"
~"[New Thread 5380.0x27ac]\n"
*running,thread-id="all"
=thread-exited,id="2",group-id="i1"
*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmentation fault",frame={addr="0x0000000000000000",func="??",args=[]},thread-id="1",stopped-threads="all"
(gdb)
<info program>
&"info program\n"
~"\tUsing the running image of child Thread 5380.0x2718.\n"
~"Program stopped at 0x0.\n"
~"It stopped with signal SIGSEGV, Segmentation fault.\n"
===WORK AROUND===
The following code does NOT throw the error. Because there was no change in the DLL, it leads me to search for the problem in FPC-side, not the within the DLL
program Test;
uses Windows;
type
CFunction = function: Integer; stdcall;
var
cryptInit, cryptEnd: CFunction;
H: THandle;
begin
H := LoadLibrary('CL64.DLL');
cryptInit := CFunction(GetProcAddress(H, 'cryptInit'));
cryptEnd := CFunction(GetProcAddress(H, 'cryptEnd'));
if cryptInit() = 0 then
Writeln('Init!');
cryptEnd();
FreeLibrary(H);
Writeln('Complete');
end.
I consider this an acceptable work-around but the programmer in me cannot let this go. Any help on compiler directives appreciated