Conversão de Variáveis Integer,String e Cardinal
10/11/2009
0
Carlos Silva
Posts
10/11/2009
Alan Souza
10/11/2009
Carlos Silva
SysUtils, Classes, Windows, Dialogs; {$R *.RES} //----------------------------------------------------------------//
{ INICIO FUNCOES DA DLL PcScale }
//----------------------------------------------------------------// {Declara a função ConfiguraBalanca existente na DLL "PcScale.dll"}
Type TConfiguraBalanca = Function (Const Balanca: Integer; Aplicativo: THandle): Boolean; stdcall; //external PcScale; {Declara a função InicializaLeitura existente na DLL "PcScale.dll"}
Type TInicializaLeitura = Function (Const Balanca: Integer): Boolean; stdcall; //external PcScale; {Declara a função ObtemInformacao existente na DLL "PcScale.dll"}
Type TObtemInformacao = Function (Const Balanca: Integer; Campo: Integer): double; stdcall; //external PcScale; {Declara a função FinalizaLeitura existente na DLL "PcScale.dll"}
Type TFinalizaLeitura = Function (Const Balanca: Integer) : Boolean; stdcall; //external PcScale; {Declara a função ExibeMsgErro existente na DLL "PcScale.dll"}
Type TEnviaPrecoCS = Function (Const Balanca : integer; Preco : double) : Boolean; stdcall; //external PcScale; {Declara a função FinalizaLeitura existente na DLL "PcScale.dll"}
Type TObtemParametrosBalanca = Function (Const Balanca: Integer; Modelo: PInteger; Porta: PInteger; BaudRate: PInteger ): Boolean; stdcall; //external PcScale; {Declara a função ObtemNomeBalanca existente na DLL "PcScale.dll"}
Type TObtemNomeBalanca = Function (Const Modelo, Ret: String): Integer; stdcall; //external PcScale; {Declara a função ExibeMsgErro existente na DLL "PcScale.dll"}
Type TExibeMsgErro = Function (Const Aplicativo : THandle): String; stdcall; //external PcScale; type
PInteger = ^Integer; var //Variaveis que armazenarão os retornos da função ObtemParametrosBalanca
Modelo, Porta, BaudRate: Integer; //Mascara para formatacao do peso com casas decimais
mascara : String; //Variável que armazenará o modelo da balança, função ObtemNomeBalanca
CModelo: array[0..50] of char; // iFuncId -> Código identificador da função
// pParametro -> Parâmetros passados para a função
// pBuffer -> Retorno da função
// iBuffer -> Tamanho do buffer de retorno pré-alocado ( São alocados 20000 Bytes por padrão ) Procedure Funcao2; Begin MessageDlg('Funcao 1', mtinformation, [mbok], 0); End; Procedure ExecInClientDLL( iFuncId : integer; pParametro, pBuffer : pChar; iBuffer : integer ); StdCall; Var
ConfiguraBalanca : TConfiguraBalanca;
InicializaLeitura : TInicializaLeitura;
LibHandle: THandle; sRetorno: String;
aParametro: Array[0..10] Of String; iParametros, iPos, iIndice: Integer; Begin Case iFuncId Of
1: Begin LibHandle := LoadLibrary (PChar (Trim ('PcScale.dll')));
If LibHandle <= HINSTANCE_ERROR Then
Raise Exception.Create ('Dll não carregada');
@ConfiguraBalanca := GetProcAddress (LibHandle, 'ConfiguraBalanca');
iParametros := 1;
sRetorno := pParametro;
While Pos(',', sRetorno) > 0 Do
Begin
sRetorno := Copy(sRetorno, Pos(',', sRetorno) + 1, Length(sRetorno));
Inc(iParametros, 1);
End;
sRetorno := pParametro; iIndice := 1;
While iIndice <= iParametros Do
Begin
If Pos(',', sRetorno) > 0 Then
iPos := Pos(',', sRetorno) - 1
Else
iPos := Length(sRetorno);
aParametro[iIndice - 1] := Copy(sRetorno, 1, iPos);
sRetorno := PChar(Copy(sRetorno, Pos(',', sRetorno) + 1, Length(sRetorno)));
Inc(iIndice, 1);
End;
sRetorno := IntToStr(ConfiguraBalanca (aParametro[0], aParametro[1]));
StrPLCopy(pBuffer , sRetorno, iBuffer); End; 2: Funcao2() End; End;
Exports ExecInClientDLL; // Essa será a única função lida pelo client do Protheus Begin End.
11/11/2009
Carlos Silva
11/11/2009
Alan Souza
ConfiguraBalanca(StrToInt(aParametro[0]),Application.Handle);
11/11/2009
Carlos Silva
11/11/2009
Carlos Silva
11/11/2009
Alan Souza
ConfiguraBalanca(StrToInt(aParametro[0],StrToInt(aParametro[1])));
12/11/2009
Carlos Silva
Clique aqui para fazer login e interagir na Comunidade :)