Histórico da Página
Composition Setup |
---|
import.css=/download/attachments/3279126062824/newLayouttecnologia.css |
|
Pagetitle | ||
---|---|---|
|
...
...
...
|
Executa
...
uma função com nome pré-determinado em uma DLL (Dynamic-link library , ou Biblioteca de vinculo dinâmica).
O nome da função que irá ser chamada é : ExecInClientDLL .
Sintaxe
Bloco de código | ||
---|---|---|
| ||
ExeDLLRun2( < nHandle >, < nOpc >, < cBuffer > )
|
Parâmetros
ExeDLLRun2 ( < nHandle>, < nOpc>, < cBuffer> ) --> nRet
...
Nome | Tipo | Descrição | Obrigatório | Referência |
---|---|---|---|---|
nHandle |
...
caractere | Indica o handle da DLL obtida através da função ExecInDLLOpen(). | X | |
nOpc |
...
numérico | Indica a opção que será executada pela DLL. | X | |
cBuffer |
...
caractere | Indica o buffer, no formato caracter, que será recebido pela DLL. |
...
Esse mesmo parametro será utilizado tanto para input de dados na DLL quanto para output de dados. | X |
...
Observações
- A variável cBuffer tem limite de
...
- 512.000 caracteres, para ser passada como referencia.
- O nome da função na DLL obrigatoriamente precisa se chamar ExecInClientDLL, lembrando que a DLL pode conter outras funções auxiliares, mas o ponto de entrada deverá ser esse nome. Ela precisa conter os seguintes parametros:
Tipo Parametro | Nome Parametro | Proósito |
---|---|---|
int | idCommand | Número para ser utilizado como tipo de comando a ser identificado do que ser executado na DLL |
char* | buffParam | Buffer contendo informações a serem passadas para a DLL |
char* | bufOutput | Buffer contendo algum possível retorno de dados. Caso a DLL não popule algum conteúdo nesse parametro, o mesmo irá ficar sendo vazio, sendo transmitido ao parametro do cBuffer do ADVPL. |
int | buffLen | Tamanho dos buffers, tanto de entrada quanto de saída |
Exemplos
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#define COMMAND1 1
#define COMMAND2 2
#define RETURN_COMMAND1 100
#define RETURN_COMMAND2 200
extern "C" __declspec(dllexport) int ExecInClientDLL(int idCommand, char * buffParam, char * buffOutput, int buffLen)
{
switch (idCommand)
{
case COMMAND1:
{
strcpy(buffOutput, "Comando 1");
return RETURN_COMMAND1;
}
case COMMAND2:
{
strcpy(buffOutput, "Comando 2");
return RETURN_COMMAND2;
}
default:
strcpy(buffOutput, "Comando inválido");
return 0;
}
}
|
Nota | ||||
---|---|---|---|---|
| ||||
Como pode ser observado, a dll desenvolvida para ser executada com a função ExeDLLRun2 tem uma assinatura diferente da utilizada em ExeDLLRun3, por isso não são compativeis e podem causar erros fatais na execução. |
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#define MB_OK 0
#define MB_OKCANCEL 1
#define MB_YESNO 4
#define MB_ICONHAND 16
#define MB_ICONQUESTION 32
#define MB_ICONEXCLAMATION 48
#define MB_ICONASTERISK 64
User Function DllTeste()
Local hHdl := 0,buffer := "",xRet1 := 0
// Abre Dll
hHdl //============================================================// DLL DE EXEMPLO EM DELPHI//============================================================library TSTDLL;uses Dialogs;{$R *.RES}function ExecInClientDLL( aFuncID: Integer; aParams: PChar; aBuff: PChar; aBuffSize: Integer ): integer; stdcall;begin if aFuncID=1 then begin // Roda opção 01 showmessage('Executando pela DLL - Texto via parametro: '+chr(13) + aParams); result:=999; end; if aFuncID=2 then begin // Roda opção 02 result:=-1; end;end;exports ExecInClientDLL;beginend.//============================================================// ROTINA EM AdvPL PARA CHAMADA DA DLL//============================================================// Abre DllhHdl := ExecInDLLOpen( " TSTDLLDllTeste.DLL dll" ) // ---------------------------------------------------------------- // Envia comando para execução, repare que estamos // usando a opção "1" no momento de chamar a DLL. // ---------------------------------------------------------------- // ExecInDllRun não retorna valor daDLLbuffer DLL buffer:= "Executando a partir daExecInDllRun ExecInDllRun2..." xRet1 :=ExecInDllRun ExeDllRun2( hHdl, 1, @buffer )alert MessageBox("Retorno daExecInDllRun ExeDllRun2: " + Alltrim(Str(xRet1)) + " - " + buffer, "ExeDllRun2", MB_ICONEXCLAMATION) // ExeDllRun2 retorna valor numérico daDLLbuffer DLL buffer:= "Executando a partir da ExeDllRun2..."nRet2 xRet2 := ExeDllRun2( hHdl,1 2, @buffer )alert MessageBox("Retorno da ExeDllRun2: " +StrZero(nRet2,3 Alltrim(Str(xRet2)) + " - " + buffer, "ExeDllRun2", MB_ICONEXCLAMATION) //ExeDllRun3 ExeDllRun2 retorna valor numérico daDLLbuffer DLL buffer:= "Executando a partir daExeDllRun3 ExeDllRun2..."nRet3 xRet3 :=ExeDllRun3 ExeDllRun2( hHdl,1 3, @buffer )alert MessageBox("Retorno daExeDllRun3 ExeDllRun2: " +StrZero(nRet3,3 Alltrim(Str(xRet3)) + " - " + buffer, "ExeDllRun2", MB_ICONEXCLAMATION) // ---------------------------------------------------------------- // Fecha aDLLExecInDllClose DLL ExecInDllClose( hHdl ) Microsiga Protheus 8.11 , TOTVS Application Server 10 , ByYou Application Server
Return
|