Página 1 de 1

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Vie Mar 22, 2013 8:40 pm
por Guest
Hi,
Are there some general guidelines, for porting over third-party
libraries, which are mingw compatible (meaning, they are compiled with
gcc), to interface with Xailer? For example, some mappings between C
data types and Xailer?
I had a nightmare of a time, trying to interface some Borland code with
Xailer, a few years ago. If there are some tips to start with, to avoid
wasting time, that would be appreciated.
Just some general suggestions, would be fine. Thanks.

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Sab Mar 23, 2013 1:56 am
por Guest
As an example of something more specific, here are the results of trying
to compile some example .c. code, in Xailer:
Compiling: XailerYap.prg...
Compiling: frmXailerYap.prg...
Compiling: TestCInterface.prg...
C:xailer3ProjectsXailerYapSourceTestCInterface.prg:28:7 : warning:
implicit declaration of function 'umask' [-Wimplicit-function-declaration]
Compiling: TestYInterface01.c...
C:xailer3Include/core.h:19:19: error: unknown type name 'DWORD'
C:xailer3Include/core.h:20:20: error: unknown type name 'HWND'
C:xailer3Include/core.h:20:31: error: unknown type name 'HWND'
C:xailer3Include/graphics.h:18:1: error: unknown type name 'BOOL'
C:xailer3Include/graphics.h:18:21: error: unknown type name 'HDC'
C:xailer3Include/graphics.h:18:30: error: unknown type name 'HBITMAP'
C:xailer3Include/Xailer.h:69:57: error: unknown type name 'BOOL'
....
....
4 Files, 4 Warnings, 126 Errors
Now, I know what the errors mean, of course. But where does Xailer have
the basic types defined?
#include "xailer.ch" is at the top of the source file, but it doesn't
seem to be sufficient to include any of the headers which define all of
these basic types.

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Sab Mar 23, 2013 2:47 am
por Guest
fyi,
For anyone who has had these kinds of problems in the past, but were
simply ignored when they asked about it, and finally just gave up -
In the case of the type errors in core.h, they can be mostly resolved,
by including windef.h, in the core.h file.
You shouldn't have to include it there, but I don't see any other way.

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Sab Mar 23, 2013 11:52 am
por jfgimenez
Dwayne,
> Are there some general guidelines, for porting over third-party
> libraries, which are mingw compatible (meaning, they are compiled with
> gcc), to interface with Xailer? For example, some mappings between C
> data types and Xailer?
When writing any C routine for [x]Harbour and/or Xailer, it's needed to
use the Harbour API in order to send and receive data between C and PRG
level. That API includes functions like hb_par*(), hb_ret*() and so on.
Xailer adds a few more ones, like XA_ObjSend*() and XA_ObjGet*().
Also, any function written in C which may be called from PRG level must
be declared as HB_FUNC( <funcname> ), HB_FUNC_STATIC( <funcname> ) or
XA_FUNC( <funcname> ). It's usual to write those functions in the same
PRG module, guarded by a #pragma BEGINDUMP and #pragma ENDDUMP
directives block.
Of course, it's needed at least a basic C knowledge. That's all. If you
have any problem when writing a "wrapper" or any other C routine, you
may ask here, providing, if possible, a small sample.
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Sab Mar 23, 2013 11:57 am
por jfgimenez
Dwayne,
> C:xailer3ProjectsXailerYapSourceTestCInterface.prg:28:7 : warning:
> implicit declaration of function 'umask'
> [-Wimplicit-function-declaration]
Just #include the header file where that function is declared. In this
case, it's io.h
> Compiling: TestYInterface01.c...
> C:xailer3Include/core.h:19:19: error: unknown type name 'DWORD'
> C:xailer3Include/core.h:20:20: error: unknown type name 'HWND'
> C:xailer3Include/core.h:20:31: error: unknown type name 'HWND'
> C:xailer3Include/graphics.h:18:1: error: unknown type name 'BOOL'
> C:xailer3Include/graphics.h:18:21: error: unknown type name 'HDC'
> C:xailer3Include/graphics.h:18:30: error: unknown type name 'HBITMAP'
> C:xailer3Include/Xailer.h:69:57: error: unknown type name 'BOOL'
You have to #include "windows.h" just before #include "xailer.h". In
most cases, those are the only header files which have to be included
(in that specific order). That is:
#include "windows.h"
#include "xailer.h"
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Sab Mar 23, 2013 11:58 am
por jfgimenez
Dwayne,
> For anyone who has had these kinds of problems in the past, but were
> simply ignored when they asked about it, and finally just gave up -
>
> In the case of the type errors in core.h, they can be mostly resolved,
> by including windef.h, in the core.h file.
>
> You shouldn't have to include it there, but I don't see any other way.
You have to #include "windows.h", as I've stated in the previous message.
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Sab Mar 23, 2013 12:02 pm
por jfgimenez
Dwayne,
> #include "xailer.ch" is at the top of the source file, but it doesn't
> seem to be sufficient to include any of the headers which define all
> of these basic types.
Xailer.ch is valid for PRG level, not for C level. Moreover, C and PRG
are at different levels, so, any header file included at PRG level is
not visible to C level, and viceversa. So, if you're using a #pragma
BEGINDUMP / #pragma ENDDUMP block, you have to #include any needed
header file inside that block. I.e.:
#include "Xailer.ch"
// here goes PRG code
#pragma BEGINDUMP
#include "windows.h"
#include "xailer.h"
// and here goes C wrappers and other C routines
#pragma ENDDUMP
// here continue the PRG code
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Sab Mar 23, 2013 2:16 pm
por Guest
Jose,
Sorry, I mean Xailer.h. That's what I placed in the c sources, but it
still generated the error.
However, after following your suggestion and placing the windows.h
BEFORE the Xailer header, it mostly worked.
There's still a couple of errors specifically related to the third party
library, but I can handle those.
Thanks for the suggestions. Can we put some of these general tips in an
official doc, or in wiki? Just this one tip - the order of the header
files - saves a lot of frustration.

Suggestions on porting some Mingw code, to call from Xailer

Publicado: Sab Mar 23, 2013 2:26 pm
por Guest
Jose,
Yes, I understand the the hbapi is needed for interfacing directly to
third party libraries, as opposed to just calling one of their
DLL-supplied functions.
And yes, I have some c knowledge, although it's been years since doing
anything hard-core.
However, it shouldn't be necessary to review C, in order to compile some
simple code, that is already mingw-compatible, inside Xailer. If you
ask me to compile or modify some standalone c code, it's not difficult.
Just looking for some general tips, for interfacing with Xailer - like
putting windows.h before xailer.h, and maybe a link to some mappings
between the C types that we find, and how we use those in Xailer/Harbour.
Anyway, the code is much closer now, thanks.