olá a todos,
Estou trabalhando em um sistema de pesagem e o fornecedor (TOLEDO DO BRASIL) me enviou juntamente com a dll um manual que mostra quais as funções e parâmetros contidos nesta dll, assim temos:
int Identificador = SetLink(int PortaSerial, int Pclock)
O comando que criei para chamar a função foi:
DLL FUNCTION SETLINK(PSerial AS _INT, PcLock AS _INT) AS _INT PASCAL FROM 'SETLINK' LIB 'PCLINK.DLL'
long Antigo = CountModulo(int Identificador, long Consecutivo)
O comando que criei para chamar a função foi:
DLL FUNCTION SETSEQU(IDENTIFICADOR AS _INT, CONSECUTIVO AS LONG) AS LONG PASCAL FROM 'COUNTMODULO' LIB 'PCLINK.DLL'
ONDE TRAVEI
long Cq = ReadModulo(int Idn,buff bru, buff liq, buff tar)
O int chamo _INT e o buff o que será? STRING? CHAR? OU O QUÊ?
Desde já agradeço a atenção dispensada.
Shirley d'Almeida
DLL Balança Toledo. Preciso de Ajuda.
Moderador: Moderadores
- rochinha
- Administrador

- Mensagens: 4664
- Registrado em: 18 Ago 2003 20:43
- Localização: São Paulo - Brasil
- Contato:
Amiguinha
Baseado no conteudo do arquivo DLL.CH voce só poderá usar as definições lá existentes para não acontecer erro de compilação.
#ifndef _C_TYPES
#define _C_TYPES
#define VOID 0
#define BYTE 1
#define CHAR 2
#define WORD 3
#ifdef __CLIPPER__
#define _INT 4 // conflicts with Clipper Int()
#else
#define _INT 7
#endif
#define BOOL 5
#define HDC 6
#define LONG 7
#define STRING 8
#define LPSTR 9
#define PTR 10
#define _DOUBLE 11 // conflicts with BORDER DOUBLE
#define DWORD 12
#endif
Conforme visto acima voce poderá usar a instrução buffer para variáveis estilo buffer como pointers, ou apontadores, então tente usar ptr pois provavelmente algumas variáveis passadas como parametro deverão ter seu valor retornado na própria variável, assim:
cVar = ReadModulo( idn, @bru, @liq, @tar)
Tente fazer uso destá classe que promete integração com DLLs se a necessidade de declará-las.
Use DLL32 FUNCTION no lugar de DLL FUNCTION pois estas DLLs fornecedidas são 32Bits.
@braços :?)
Baseado no conteudo do arquivo DLL.CH voce só poderá usar as definições lá existentes para não acontecer erro de compilação.
#ifndef _C_TYPES
#define _C_TYPES
#define VOID 0
#define BYTE 1
#define CHAR 2
#define WORD 3
#ifdef __CLIPPER__
#define _INT 4 // conflicts with Clipper Int()
#else
#define _INT 7
#endif
#define BOOL 5
#define HDC 6
#define LONG 7
#define STRING 8
#define LPSTR 9
#define PTR 10
#define _DOUBLE 11 // conflicts with BORDER DOUBLE
#define DWORD 12
#endif
Conforme visto acima voce poderá usar a instrução buffer para variáveis estilo buffer como pointers, ou apontadores, então tente usar ptr pois provavelmente algumas variáveis passadas como parametro deverão ter seu valor retornado na própria variável, assim:
cVar = ReadModulo( idn, @bru, @liq, @tar)
Tente fazer uso destá classe que promete integração com DLLs se a necessidade de declará-las.
Código: Selecionar todos
#include "fivewin.ch"
#define _TEST_ //Comment this line to skip test
#ifdef _TEST_
Function Test()
Local c:="hErE iS mY tEsT tExT: äâ"
MsgInfo( tDLL():New("user32","CharUpperA",LPSTR,.t.,{LPSTR}):Exec32(c), 'CharUpperA in user32')
MsgInfo( tDLL():New("user32","CharLowerA",LPSTR,.t.,{LPSTR}):Exec32(c), 'CharLowerA in user32')
return
#endif
******************************************************************************
* CLASS to access any DLL function without explicite declaring
*
* César E. Lozada (cesarlozada@hotmail.com)
* 01-Nov-2002
*
* I'm tired for writing DLL32 FUNCTION blah blah blah....
* I'll use an object for that
*
* Sintax to define object
* oDll:=tDLL():New(cDllName,cFunction,nResultType,lPascal,aParamType)
* where
* cDllName is the DLL's name
* cFunction is the function into the DLL
* nResultType is the function result type
* lPascal is .T. if PASCAL (default .T.) (I don't know what it means)
* aParamType is an array whith parameters type,
* ex.: {LONG,LONG,LONG,LPSTR,LONG,LONG} or easier
* {{LONG,3},LPSTR,{LONG,2}} //3 LONG's + 1 LPSTR + 2 LONGs
* //in this order
* ... for calling the function
*
* uRes:=oDll:Exec32([p01,p02,p03,p04,p05,p06,p07,p08,p09,p10 ]) for a DLL32, or
*
* uRes:=oDll:Exec16([p01,p02,p03,p04,p05,p06,p07,p08,p09,p10 ]) otherwise
*
* p01..p10 are the function parameteres
******************************************************************************
#xTranslate nTrim(<n>) => LTrim(Str(<n>))
******************************************************************************
CREATE CLASS tDLL
DATA cDllName
DATA aParamType
DATA cFunction
DATA nResultType
DATA lPascal INIT .T.
DATA hDll //Error code
METHOD New(cDllName,cFunction,nResultType,lPascal,aParamType) CONSTRUCTOR
METHOD Exec16(p01,p02,p03,p04,p05,p06,p07,p08,p09,p10)
METHOD Exec32(p01,p02,p03,p04,p05,p06,p07,p08,p09,p10)
METHOD Exec() LOCAL
ENDCLASS
*=============================================================================
METHOD New(cDllName,cFunction,nResultType,lPascal,aParamType)
DEFAULT nResultType:=LONG, lPascal:=.T., aParamType:={}
cFunction:=AllTrim(cFunction)
BYNAME cDllName,cFunction,nResultType,lPascal,aParamType
return
*=============================================================================
METHOD Exec16(p01,p02,p03,p04,p05,p06,p07,p08,p09,p10)
return ::Exec(.f., @p01,@p02,@p03,@p04,@p05,@p06,@p07,@p08,@p09,@p10)
*=============================================================================
METHOD Exec32(p01,p02,p03,p04,p05,p06,p07,p08,p09,p10)
return ::Exec(.t., @p01,@p02,@p03,@p04,@p05,@p06,@p07,@p08,@p09,@p10)
*=============================================================================
METHOD Exec(l32,p01,p02,p03,p04,p05,p06,p07,p08,p09,p10)
Local uResult, cFarProc, cMacro
Local n,m
::hDLL:=LoadLib32(::cDllName)
IF Abs(::hDLL)<=32
MsgAlert( "Error code: " + nTrim( ::hDLL ) + " loading " + ::cDllName )
ELSE
cMacro:=if(l32,[GetProc32],[GetProcAddress])+[(]+nTrim(::hDLL)+;
[,"]+::cFunction+["]+;
[,]+if(::lPascal,'.t.','.f.')+;
[,]+nTrim(::nResultType)
for n:=1 to Len(::aParamType)
IF ValType(::aParamType[n])="A"
for m:=1 to ::aParamType[n,2]
cMacro+=[,]+nTrim(::aParamType[n,1])
next
ELSE
cMacro+=[,]+nTrim(::aParamType[n])
ENDIF
next
cMacro+=[)]
cFarProc:=&cMacro
if l32
uResult:=CallDll32(cFarProc,p01,p02,p03,p04,p05,p06,p07,p08,p09,p10)
FreeLib32(::hDLL)
else
uResult:=CallDll(cFarProc,p01,p02,p03,p04,p05,p06,p07,p08,p09,p10)
FreeLibrary(::hDLL)
endif
ENDIF
return uResult
******************************************************************************
*
* Some useful functions
*
* aPoints:={{0,0}, {100,0}, {100,100}, {0,100}}
* cLPSTR:=aLong2LPSTR(aPoints)
* oDLL:=tDLL():New('gdi32','Polygon',LONG,.t.,{LONG,LPSTR,LONG})
* oDLL:Exec32(hDC,cLPSTR,Len(aPoints))
*
******************************************************************************
Function aLong2LPSTR(aArr)
*----
* Converts a LONGs' array into a LPSTR
*----
Local cLPSTR:=''
aEval(aArr,{|u| _t:=ValType(u),;
cLPSTR+=if(_t="N",L2Bin(u),if(_t="A",aLong2LPSTR(u),'')) })
return cLPSTR
******************************************************************************
Function LPSTR2aLong(cLPSTR,nCols)
*----
* Converts a LPSTR into a LONGs' array every row having nCols columns
*----
Local aArr:={}, p:=1
DEFAULT nCols:=0
DO WHILE p<=Len(cLPSTR)
if nCols=0
aAdd(aArr,Bin2L(SubStr(cLPSTR,p,4)))
p+=4
else
aAdd(aArr,LPSTR2aLong(SubStr(cLPSTR,p,4*nCols),0))
p+=4*nCols
endif
ENDDO
return aArr
******************************************************************************
@braços :?)
