The program completely crashes if I put any code anywhere which calls any of the dll functions.

Let's take a more easier function first. I have converted:

Code:
GL2PSDLL_API GLint gl2psEndPage(void);
into

Code:
function gl2psEndPage(): GLInt; stdcall; external 'gl2ps.dll';
Now if I add the code:

Code:
var
 state: GLInt;
begin
 state := gl2psEndPage();
The application completely crashed before even showing any of the information. Compiling works but executing gives me an error and won't start, until I comment those lines.

Here is what the compiler says:

Module Load: COMDLG32.dll. No Debug Info. Base Address: $75E30000. Process General.exe (3976)
Module Load: UNKNOWN_MODULE_11. No Debug Info. Base Address: $67660000. Process General.exe (3976)
Module Load: MSVCR100D.dll. No Debug Info. Base Address: $5F4D0000. Process General.exe (3976)
Debug Output: *** A stack buffer overrun occurred in "C:\...\General.exe" : Process General.exe (3976)
Debug Output: This is usually the result of a memory copy to a local buffer or structure where the size is not properly calculated/checked. Process General.exe (3976)
Debug Output: If this bug ends up in the shipping product, it could be a severe security hole. Process General.exe (3976)
Debug Output: The stack trace should show the guilty function (the function directly above __report_gsfailure). Process General.exe (3976)
Debug Output: *** enter .exr 770B9310 for the exception record Process General.exe (3976)
Debug Output: *** then kb to get the faulting stack Process General.exe (3976)