Prof A Olowofoyeku wrote:
There is something else which has been exercising me, in respect of imports from Windows DLLs. In gcc, I can do something like this:
FARPROC foo; /*pointer to DLL function "char *foo (char *x, char * y, int z)" */
void main(){ char *str; HINSTANCE h = LoadLibrary ("myfoo.dll"); if (h > 0) { foo = GetProcAddress (h, "foo@12"); str = foo ("foo", "bar", 24); } }
In GPC, this kind of thing will (naturally) not work, because the (function) pointer "foo" cannot be passed arbitrary parameters like that. gcc happily accepts it (now, of course, if the parameters are wrong, then the program will GPF at the call "str = foo ...", and if the parameters are correct, then everything works correctly).
The question is: since GPC is based on gcc, is the capacity to accept something like this present in GPC? (the question whether it should be accepted of is of course a different thing). I personally would find it very useful (not for translating c headers, but for automated parsing of DLLs and automated imports of their exported symbols), although I can hear all the cries of "Pascal is a safe language and therefore should never accept something like this".
GPC allows the following:
program foo; type fsi = function(s : string): integer; var fp : fsi; i : integer; function GetProcAddress : pointer; begin GetProcAddress := nil end; begin fp := fsi(GetProcAddress); i := fp('') end .
Of course, since my `GetProcAddress' return nil it will crash at runtime. However, with proper external declaration of `GetProcAddress' and `LoadLibrary' and assuming that fsi is correct it should work. On Windows you have to remember to use correct calling convention, but that is not different that calling external functions via import librarires.
So, AFAICS you can not entiterly omit info about arguments, but you can declare function variable of correct type and assign (casted) result of `GetProcAddress' to it.