parameter function as structure

parameter function as structure

Postby kajot » Sat Aug 28, 2010 6: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
User avatar
kajot
 
Posts: 332
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: parameter function as structure

Postby Antonio Linares » Sat Aug 28, 2010 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41436
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: parameter function as structure

Postby Antonio Linares » Sat Aug 28, 2010 7:50 am

Code: Select all  Expand view
#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: Select all  Expand view

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
User avatar
Antonio Linares
Site Admin
 
Posts: 41436
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: parameter function as structure

Postby kajot » Sun Aug 29, 2010 8: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
User avatar
kajot
 
Posts: 332
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: parameter function as structure

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41436
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: parameter function as structure

Postby kajot » Sun Aug 29, 2010 2: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, "Mleko", "2", "A", "10.5", "21", "0", ""})


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
User avatar
kajot
 
Posts: 332
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: parameter function as structure

Postby Antonio Linares » Sun Aug 29, 2010 4: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41436
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: parameter function as structure

Postby kajot » Sun Aug 29, 2010 5: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
User avatar
kajot
 
Posts: 332
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: parameter function as structure

Postby Antonio Linares » Tue Aug 31, 2010 9:30 am

Kajot,

Please add

#include <hbapi.h>

after:

#pragma BEGINDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41436
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 50 guests