Hi
I have found a possible problem, illustrated in the three programs below (and in the comments):
program one; uses windows; var h : THandle = LoadLibrary ('winstl32.dll'); v : ^function : integer = GetProcAddress (h, 'Chief32DllVersion'); begin Writeln ('Handle=', h); Writeln ('V is assigned=', Assigned (v)); { TRUE } Writeln ('Version=', v^); { correct result } Writeln ('DLL Unloaded=',FreeLibrary (h)); { TRUE } end.
program two; uses windows; var h : THandle = LoadLibrary ('winstl32.dll'); v : function : integer = GetProcAddress (h, 'Chief32DllVersion'); begin Writeln ('Handle=', h); Writeln ('V is assigned=', Assigned (v)); { TRUE } Writeln ('Version=', v); { wrong result } Writeln ('DLL Unloaded=',FreeLibrary (h)); { TRUE } end.
program three; uses windows; var h : THandle = LoadLibrary ('winstl32.dll'); v : function : integer = GetProcAddress (h, 'Chief32DllVersion'); begin Writeln ('Handle=', h); Writeln ('V is assigned=', Assigned (v)); { TRUE } @v := GetProcAddress (h, 'Chief32DllVersion'); { saves the day } Writeln ('Version=', v); { correct result } Writeln ('DLL Unloaded=', FreeLibrary (h)); { TRUE } end.
What is the possible problem?
1. With all programs, declarations of "h" and "v" are accepted by GPC. But they are not accepted by Delphi, FreePascal, VirtualPascal, or BP ("cannot evaluate this expression" or "constant expression expected"). Is this an EP thing or is it a GPC extension?
BTW: gcc (Mingw) doesn't accept this type of initialisation.
2. As you can see from the comments, the assignment of "v" to GetProcAddress ... seems to succeed (in that the variable is indeed assigned), but silently produces a wrong result, meaning that it didn't really get assigned as it should.
Any comments? Thanks.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/