On Wed, 16 May 2001, Prof. A Olowofoyeku (The African Chief) wrote:
On 16 May 2001, at 15:29, Matthias Braun wrote:
[...]
A typical line from allunit.pas is: var screen: BITMAP_ptr; asmname 'screen'; external; this produces a screen not found when linking the thing, however, linking the C files suceed. So I looked at the symbols with objdump -t -T, and saw that the C object files use __imp_screen instead of _screen, although C Declaration is also BITMAP *screen;
So I tried to changed the code to screen : BITMAP_ptr; asmname '_impl__screen'; external; which linked ok, but produced crashing progs. After some investigation, I discovered, that these __imp_screen, aren't the global var itself but a pointer to the var.
Yes. Isn't that what the "*" in the declaration means?
No. It's a pointer to a pointer to a BITMAP. I missinterpreted C declaration stuff (There are complicated preprocessor things) The correct declaration is: extern __attribute__((dllimport)) BITMAP *screen;
So the thing seems to be the dllimport. But when using dllimport with variables, gpc sometimes seems to do nothing (if attribute(dllimport) stands after asmname), or gets confused (if it stands direct after the var declaration).
I tried to use it with functions and procedures and then it does the right thing: It adds a __imp__ in front of the symbol name. So this looks to me like a compiler bug.
Am I doing something wrong or can't gpc handle dll stuff right?
GPC can handle dll stuff quite fine. The entire Win32 API is dll-based, and GPC programs can use the API with no problem. You need to make sure that you are dereferencing the pointers where appropriate. But may also need to attach the "stdcall" attribute to the DLL function imports. What I do to simply it all is this;
{$define Stdcall attribute(stdcall)} {$define WINAPI(X) asmname X; Stdcall} FUNCTION GetDC ( Wnd : HWND ) : HDC; WINAPI ( 'GetDC' ); blah, blah ....
Thanks, didn't know that. But Allegro Library consisted of 2 libs anyway: the all3936.dll and liballeg.a, and I link the liballeg.a with my programs, which seems to be a wrapper to the lib. I don't need to define the procedures and functions like this, it's working with a simpel "C;".
Matze