Forum > Beginners

How to start 'XOpenDisplay' in libX11.so.6.3.0

(1/1)

ciammaruca:
hi,
i can't open a connection to X server, i can't create a display with XOpenDisplay.
i can see this:
http://user.xmission.com/~georgeps/documentation/tutorials/Xlib_Beginner.html
or i can see what happens in gambas, where a simple pointer can open a display, as you can find here:
http://www.gambas-it.org/wiki/index.php?title=Creare_una_finestra_mediante_le_funzioni_del_API_di_X11
at lines:
Private disp As Pointer
disp = XOpenDisplay(Null)

So, i've also tried to use the H2pas converted Xlib.h, in this way:
uses
  Classes, SysUtils, dynlibs,unit1,Xlib;
....
disp : PDisplay;
P : PChar;

implementation
begin

 Mylib_handle:= LoadLibrary('libX11.so.6.3.0');
   if Mylib_handle = dynlibs.NilHandle then Exit;  //DLL was not loaded successfully
   P :=':0.0';
   Pointer(TXOpenDisplay):=DynLibs.GetProcedureAddress(mylib_handle,PChar('TXOpenDisplay'));
   disp:= TXOpenDisplay(p);

but at the last line an error comes out

cryptkeeper:
maybe you could start from this:
http://wiki.freepascal.org/X11

Fred vS:
Hello.

Some remarks =>

What kind of function/procedure is TXOpenDisplay(?) ?
You should declare/use it like that :


--- Code: ---uses
...,
 DynLibs.pas,...
...
var
TXOpenDisplay: function(mystr : PChar): PChar ; cdecl; // or whatever declared in library.
...
implementation
...
Pointer(TXOpenDisplay):=DynLibs.GetProcedureAddress(mylib_handle,PChar('TXOpenDisplay'));
...

--- End code ---

Also, for  Mylib_handle := LoadLibrary('libX11.so.6.3.0');  => it is a good idea to use the full path of library...

Fre;D

ciammaruca:
hi,
ok, but after:
   Pointer(TXOpenDisplay):=DynLibs.GetProcedureAddress(mylib_handle,PChar('TXOpenDisplay'));
i have to pass value to TXOpenDisplay, and then to call TXDefaultScreen, isn't it? So:
var
TXDefaultScreen : function(displayP : PChar) : Longint; cdecl;
 screen: Longint;
P : PChar;
 ...
implementation
...
  Pointer(TXOpenDisplay):=DynLibs.GetProcedureAddress(mylib_handle,PChar('TXOpenDisplay'));
  Pointer(TXDefaultScreen):= DynLibs.GetProcedureAddress(mylib_handle,PChar('TXDefaultScreen'));
   p:=':0.0';
   screen:=TXDefaultScreen(TXOpenDisplay(p));

but TXOpenDisplay(p) returns error

Fred vS:
Hello.

The most important is to tell to fpc what function/procedure with what arguments is exported from the library.
AFAIK, fpc can not do like Python (who can see/define arguments/function/procedure exported by the foreign library).

So you have to find the C header for that library and translate each function/procedure in Pascal code.

=>
--- Code: ---TXOpenDisplay: function(mystr : PChar): PChar ; cdecl; // or whatever declared in library.
--- End code ---

=> It is a example, i do not know what is exported in libX11.so.6.3.0

Navigation

[0] Message Index

Go to full version