FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour parameter function as structure
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM

parameter function as structure

Posted: Sat Aug 28, 2010 06:08 AM

I want to use function LBTRSLN from ThermalServiceLibrary.dll,

def function

int LBTRSLN(
tLBTRSLN_PARAMS * aLBTRSLN_ParamsPtr
);

and

aLBTRSLN_ParamsPtr
address stucture tLBTRSLN_PARAMS

tLBTRSLN_PARAMS

typedef struct
{
BYTE Pi;
BYTE Pr;
char * Name;
tEXTERNAL_NUMERIC Quantity;
char Vat;
tEXTERNAL_NUMERIC Price;
tEXTERNAL_NUMERIC Gross;
tEXTERNAL_NUMERIC Discount;
} tLBTRSLN_PARAMS;

how may I relay parameters to this functions

best regards
kajot

best regards

kajot
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: parameter function as structure

Posted: Sat Aug 28, 2010 07:42 AM

Kajot,

You may build a C function that receives an array with all the structure values and then from C you build the structure from the array and call the original function :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: parameter function as structure

Posted: Sat Aug 28, 2010 07:50 AM
Code (fw): Select all Collapse
#pragma BEGINDUMP 

HB_FUNC( LBTRSLN )
{
   tLBTRSLN_PARAMS aLBTRSLN_Params;

   aLBTRSLN_Params.Pi = hb_parnl( 1, 1 );
   aLBTRSLN_Params.Pr = hb_parnl( 1, 2 );
   aLBTRSLN_Params.Name = hb_parc( 1, 3 );
   aLBTRSLN_Params.Quantity = hb_parnl( 1, 4 );
   aLBTRSLN_Params.Vat = hb_parnl( 1, 5 );
   aLBTRSLN_Params.Price = hb_parnl( 1, 6 );
   aLBTRSLN_Params.Gross = hb_parnl( 1, 7 );
   aLBTRSLN_Params.Discount = hb_parnl( 1, 8 );

   hb_retnl( LBTRSLN( &aLBTRSLN_Params ) );
}
#pragma ENDDUMP

From PRG you do:
Code (fw): Select all Collapse
MsgInfo( LBTRSLN( { 1, 2, ... } )

You may need to use a define or a header file for tEXTERNAL_NUMERIC as that is not a standard Windows type. I have assumed that it is equivalent to a 32 bits number.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM

Re: parameter function as structure

Posted: Sun Aug 29, 2010 08:21 AM

thanks for it

and one question yet

how define in
DLL32 Function LBTRSLN( ??? ) As INT PASCAL LIB "ThermalStructureLibrary.dll"

best redards
kajot

best regards

kajot
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: parameter function as structure

Posted: Sun Aug 29, 2010 10:27 AM

Kajot,

In this case you should not use the command DLL FUNCTION ...

Instead of it, create an import library from the DLL and link it to your EXE:
implib.exe ThermalStructureLibrary.lib ThermalStructureLibrary.dll

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM

Re: parameter function as structure

Posted: Sun Aug 29, 2010 02:55 PM

I created ThermalServiceLibrary.Lib / by implib.exe/
I go during linking error

Type: C >>>xhb.exe -o"t.c" -m -n -p -q -gc0 -I"D:\xHB.112\include" -I"D:\xHB.112\include\w32" "t.prg"<<<

xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6633)
Copyright 1999-2009, http://www.xharbour.org http://www.harbour-project.org/
Generating object output to 't.obj'...
t.prg(20): error: Undeclared identifier 'tLBTRSLN_PARAMS'.

t.prg(20): error: Syntax error; found 'aLBTRSLN_Params' expecting ';'.

t.prg(20): error: Undeclared identifier 'aLBTRSLN_Params'.

t.prg(21): error: Left operand of . has incompatible type 'int'.

t.prg(22): error: Left operand of . has incompatible type 'int'.

t.prg(23): error: Left operand of . has incompatible type 'int'.

t.prg(23): warning: Conversion from 'char *' to 'int' is undefined.

t.prg(24): error: Left operand of . has incompatible type 'int'.

t.prg(25): error: Left operand of . has incompatible type 'int'.

t.prg(26): error: Left operand of . has incompatible type 'int'.

t.prg(27): error: Left operand of . has incompatible type 'int'.

t.prg(28): error: Left operand of . has incompatible type 'int'.

t.prg(29): warning: Missing prototype for 'LBTRSLN'.

Type: C >>>Couldn't build: t.obj<<<
Type: C >>>TMAKEOBJECT<<<
Type: C >>>TMAKEOBJECT:REFRESH<<<
Type: N >>> 1423<<<

my source:

include "wintypes.ch"

Include "cstruct.ch"

include "hbdll.ch"


procedure t

setmode(25,80)
cls
LBTRSLN({ 1, 1, 1, &quot;Mleko&quot;, &quot;2&quot;, &quot;A&quot;, &quot;10.5&quot;, &quot;21&quot;, &quot;0&quot;, &quot;&quot;})

return

pragma BEGINDUMP

HB_FUNC( LBTRSLN )
{
tLBTRSLN_PARAMS aLBTRSLN_Params;
aLBTRSLN_Params.Pi = hb_parnl( 1, 1 );
aLBTRSLN_Params.Pr = hb_parnl( 1, 2 );
aLBTRSLN_Params.Name = hb_parc( 1, 3 );
aLBTRSLN_Params.Quantity = hb_parnl( 1, 4 );
aLBTRSLN_Params.Vat = hb_parnl( 1, 5 );
aLBTRSLN_Params.Price = hb_parnl( 1, 6 );
aLBTRSLN_Params.Gross = hb_parnl( 1, 7 );
aLBTRSLN_Params.Discount = hb_parnl( 1, 8 );
hb_retnl( LBTRSLN( &aLBTRSLN_Params ) );
}

pragma ENDDUMP

best regards
kajot

best regards

kajot
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: parameter function as structure

Posted: Sun Aug 29, 2010 04:18 PM

Kajot,

Include this after #pragma BEGINDUMP

define BYTE unsigned char

define tEXTERNAL_NUMERIC unsigned long

typedef struct
{
BYTE Pi;
BYTE Pr;
char * Name;
tEXTERNAL_NUMERIC Quantity;
char Vat;
tEXTERNAL_NUMERIC Price;
tEXTERNAL_NUMERIC Gross;
tEXTERNAL_NUMERIC Discount;
} tLBTRSLN_PARAMS;

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM

Re: parameter function as structure

Posted: Sun Aug 29, 2010 05:27 PM

sorry yet one error

Type: C >>>xhb.exe -o"t.c" -m -n -p -q -gc0 -I"D:\xHB.112\include" -I"D:\xHB.112\include\w32" "t.prg"<<<

xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6633)
Copyright 1999-2009, http://www.xharbour.org http://www.harbour-project.org/
Generating object output to 't.obj'...
t.prg(36): warning: Missing prototype for 'LBTRSLN'.

Type: C >>>xlink.exe -NOEXPOBJ -MAP -FORCE:MULTIPLE -NOIMPLIB -subsystem:console -LIBPATH:"D:\xHB.112\lib" -LIBPATH:"D:\xHB.112\c_lib" -LIBPATH:"D:\xHB.112\c_lib\win" "t.obj" "cdll.obj" "R:\lib\WinApi.lib" "R:\lib\ThermalServiceLibrary.lib" "xhb.lib" "dbf.lib" "nsx.lib" "ntx.lib" "cdx.lib" "rmdbfcdx.lib" "ct3comm.lib" crt.lib kernel32.lib user32.lib winspool.lib ole32.lib oleaut32.lib odbc32.lib odbccp32.lib uuid.lib wsock32.lib ws2_32.lib wininet.lib advapi32.lib shlwapi.lib msimg32.lib mpr.lib -out:"t.exe"<<<

Creating object: t.EXP

Creating library: t.LIB

xLINK: error: Unresolved external symbol '_LBTRSLN referenced from (t.obj)'.

xLINK: fatal error: 1 unresolved external(s).

Type: C >>>Couldn't build: t.exe<<<
Type: C >>>TMAKEPROJECT<<<
Type: C >>>TMAKEPROJECT:REFRESH<<<
Type: N >>> 1423<<<

my source:

include "wintypes.ch"

Include "cstruct.ch"

include "hbdll.ch"


pragma BEGINDUMP

define BYTE unsigned char

define tEXTERNAL_NUMERIC unsigned long

typedef struct
{
BYTE Pi;
BYTE Pr;
char * Name;
tEXTERNAL_NUMERIC Quantity;
char Vat;
tEXTERNAL_NUMERIC Price;
tEXTERNAL_NUMERIC Gross;
tEXTERNAL_NUMERIC Discount;
} tLBTRSLN_PARAMS;

HB_FUNC( LBTRSLN )
{
tLBTRSLN_PARAMS aLBTRSLN_Params;
aLBTRSLN_Params.Pi = hb_parnl( 1, 1 );
aLBTRSLN_Params.Pr = hb_parnl( 1, 2 );
aLBTRSLN_Params.Name = hb_parc( 1, 3 );
aLBTRSLN_Params.Quantity = hb_parnl( 1, 4 );
aLBTRSLN_Params.Vat = hb_parnl( 1, 5 );
aLBTRSLN_Params.Price = hb_parnl( 1, 6 );
aLBTRSLN_Params.Gross = hb_parnl( 1, 7 );
aLBTRSLN_Params.Discount = hb_parnl( 1, 8 );
hb_retnl( LBTRSLN( &aLBTRSLN_Params ) );
}

pragma ENDDUMP

procedure t

setmode(25,80)
cls

// OpenPort("Com4")

// 'nagłówek
// LBTRSHDR({0, 0, "Ala ma kota", "", ""})

// '2 linie z towarami
LBTRSLN({ 1, 1, 1, "Mleko", "2", "A", "10.5", "21", "0", ""})
// LBTRSLN({ 1, 1, 1, "Chleb", "10", "A", "1.49", "14.9", "0", ""})

// 'podsumowanie
// LBTRXEND1({ 1, 1, 1, "0", "35.9", "40", "4.1", "", ""})

// ClosePort()

return

best regards

kajot
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: parameter function as structure

Posted: Tue Aug 31, 2010 09:30 AM

Kajot,

Please add

include <hbapi.h>

after:

pragma BEGINDUMP

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion