Código: Selecionar todos
Por ser modo Console? Não consigo enxergar onde esta o meu erro... SorryMande para mim uma rotina simples, contendo apenas consulta de status do sat, que vou testar aqui.
Moderador: Moderadores

Código: Selecionar todos
Por ser modo Console? Não consigo enxergar onde esta o meu erro... Sorry
Código: Selecionar todos
#include "hmg.ch"
#include "dll.ch"
function Main()
PUBLIC hACBrDLL
cPath := cFilePath( GetModuleFileName( GetInstance() ) ) // Pega o caminho exato onde se encontra o sistema.
? "SAT.dll carregada",;
hACBrDLL := LoadLibrary( cPath+"SAT.DLL" )
? "ConsultarSAT",;
ConsultarSAT( Random( 999999 ) ) //[3]
return nil
Function ConsultarSAT( nSessionRandom )
cString := SATConsultar( nSessionRandom )
return StringToArray( cString, "|" )
DLL32 FUNCTION SATConsultar( nSessionRandon AS _INT ) AS STRING PASCAL FROM "ConsultarSAT" LIB hACBrDLL
Function Random( nMaximo )
static nRandom
local nTemporal
nMaximo = if( nMaximo == NIL, 65535, nMaximo )
if nRandom == NIL
nRandom = seconds()
endif
nTemporal = ( nRandom * seconds() ) % ( nMaximo + 1 )
nTemporal = if( nTemporal < 1, 1, nTemporal )
nRandom = nTemporal + seconds()
RETURN int( nTemporal )
function StringToArray( cString, cSeparator )
LOCAL nPos
LOCAL aString := {}
DEFAULT cSeparator := ";"
cString := ALLTRIM( cString ) + cSeparator
DO WHILE .T.
nPos := AT( cSeparator, cString )
IF nPos = 0
EXIT
ENDIF
AADD( aString, SUBSTR( cString, 1, nPos-1 ) )
cString := SUBSTR( cString, nPos+1 )
ENDDO
RETURN ( aString )
Código: Selecionar todos
#ifndef _DLL_CH
#define _DLL_CH
#define VOID 0
#define BYTE 1
#define CHAR 2
#define WORD 3
#define INT 4
#define BOOL 5
#define HDC 6
#define LONG 7
#define STRING 8
#define LPSTR 9
#define PTR 10
#xcommand DLL FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
[, <uParamN> AS <typeN> ] ) ;
AS <return> [<pascal:PASCAL>] LIB <*DllName*> ;
=> ;
function <FuncName>( [<uParam1>] [,<uParamN>] ) ;;
local hDLL := LoadLibrary( <(DllName)> ) ;;
local cFarProc ;;
local uResult ;;
if hDLL != 0 ;;
cFarProc = GetProcAddress( hDLL, <(FuncName)>, [<.pascal.>], <return>, <type1> [,<typeN>] ) ;;
uResult = CallDLL( cFarProc, [<uParam1>] [,<uParamN>] ) ;;
FreeLibrary( hDLL ) ;;
end ;;
return uResult
#endif
#xcommand DLL32 [<static:STATIC>] FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
[, <uParamN> AS <typeN> ] ) ;
AS <return> [<pascal:PASCAL>] [ FROM <SymName> ] LIB <*DllName*> ;
=> ;
[<static>] function <FuncName>( [NOREF(<uParam1>)] [,NOREF(<uParamN>)] ) ;;
local hDLL := If( ValType( <DllName> ) == "N", <DllName>, LoadLib32( <(DllName)> ) ) ;;
local uResult ;;
local cFarProc ;;
if Abs( hDLL ) <= 32 ;;
MsgAlert( "Error code: " + LTrim( Str( hDLL ) ) + " loading " + <DllName> ) ;;
else ;;
cFarProc = GetProc32( hDLL,;
If( [ Empty( <SymName> ) == ] .t., <(FuncName)>, <SymName> ),;
[<.pascal.>], <return> [,<type1>] [,<typeN>] ) ;;
uResult = CallDLL32( cFarProc [,<uParam1>] [,<uParamN>] ) ;;
If( ValType( <DllName> ) == "N",, FreeLib32( hDLL ) ) ;;
end ;;
return uResult

Código: Selecionar todos
FUNCTION sat_status
Local r:= HB_RandomInt(999999) , xRet, cSessao, cMensagem, cResp
SetMode(25,80)
h1:= LoadLibrary("SAT.DLL")
if h1 = 0
alert( 'dll não carregada !' )
return .f.
endif
ret:= dllcall(h1,32,"ConsultarSAT",r)
xRet:= HB_Pointer2String(ret,100)
cSessao:= left(xRet,6)
cResp:= subs(xRet,8,5)
cMensagem:= subs(xRet,14)
if cResp = '08000'
tone(196,5)
tone(296,5)
tone(396,5)
alert( ValtoPrg(xRet) )
else
alert( cResp )
endif
freelibrary(h1)
return







Código: Selecionar todos
#include "hbwin.ch"
#include "hbdyn.ch"
function main()
ConsultaSAT()
@ 23,01 SAY "FIM DA EXECUCAO"
INKEY(0)
FUNCTION CONSULTASAT()
Local r:= HB_RandomInt(999999) , xRet, cSessao, cMensagem, cResp
SetMode(25,80)
h1:= HB_Libload("C:\SAT\SAT.DLL")
@ 01,01 SAY H1
INKEY(1)
ret:= HB_DynCall( {"ConsultarSAT",h1},r)
@ 02,01 SAY ret
INKEY(1)
xRet := HB_Pointer2String(ret,100)
cSessao := left(xRet,6)
cResp := subs(xRet,8,5)
cMensagem:= subs(xRet,14)
@ 03,01 SAY XRET
if cResp = '08000'
tone(196,5)
tone(296,5)
tone(396,5)
alert( ValtoPrg(xRet) )
else
alert( cResp )
endif
hb_LibFree(h1)
return
