Histórico da Página
Composition Setup |
---|
import.css=/download/attachments/3279126062824/newLayouttecnologia.css |
|
Pagetitle |
---|
...
|
...
Função: ExecInDLLRun
Executa functions ou procedures de uma determinada DLL - Dynamic-link library (Biblioteca de ligação dinâmica).
ExecInDLLRun ( < nHandle>, < nOpc>, < cBuffer> ) --> Nil
...
|
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 | ||
---|---|---|
| ||
cRet := ExecInDllRun( < nHandle >, < nOpc >, < cStrInput > )
|
Parâmetros
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 |
...
cStrInput |
...
caractere | Indica o buffer, no formato caracter, que será recebido pela DLL. |
...
...
Esse mesmo parametro será utilizado apenas para input de dados na DLL. Caso seja necessário informar um parâmetro maior, utilize a função ExeDLLRun2. | X |
Retorno
O retorno da função será um buffer no formato caracter de até 255 bytes.
Exemplo (DLL)
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
// Fonte de exemplo c++
// Deve ser compilado gerando uma DLL 32 bits, chamada "tstdll.dll"
// para ser usada no exemplo em AdvPL. Esta DLL deve ser copiada para a pasta do SmartClient.EXE
extern "C" __declspec(dllexport) void ExecInClientDLL(int idCommand, char * buffParam, char * buffOutput, int buffLen)
{
switch (idCommand)
{
case COMMAND1:
{
strcpy(buffOutput, "Comando 1");
return;
}
case COMMAND2:
{
strcpy(buffOutput, "Comando 2");
return;
}
default:
strcpy(buffOutput, "Comando inválido");
return;
}
}
|
Observações
- A função executada dentro da DLL pode escrever um retorno em string de até 255 bytes. Caso seja necessário um retorno maior, utilize a função ExeDLLRun2.
- Para o nome da função na DLL, é obrigatorio utilizar ExecInClientDLL, com a declaração/assinatura abaixo especificada, para o correto funcionamento da implementação.
Nota | ||||
---|---|---|---|---|
| ||||
Como pode ser observado, a dll desenvolvida para ser executada com a função ExecinDLLRun tem uma assinatura diferente da utilizada em ExeDLLRun3, por isso não são compatíveis e podem causar erros fatais na execução. Quando a função ExecInClientDLL é chamada através da função AdvPL ExecInDLLRun(), o buffer de retorno suporta apenas 255 bytes. Caso seja necessário um retorno maior, utilize a função ExeDLLRun2() |
Exemplo (AdvPL)
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#define MB_OK (). A variável cBuffer tem limite de 259 caracteres, para ser passada como referencia.//============================================================// DLL DE EXEMPLO EM DELPHI//============================================================library TSTDLL;uses Dialogs;{$R *.RES}function ExecInClientDLL( aFuncID: Integer; aParams: PChar;0 #define MB_OKCANCELaBuff: PChar;1 #define MB_YESNOaBuffSize: Integer ): integer; stdcall;begin if aFuncID=1 then begin4 #define MB_ICONHAND// Roda opção 01 showmessage('Executando pela DLL - Texto via parametro: '+chr(13) + aParams);16 #define MB_ICONQUESTIONresult:=999; end; if aFuncID=2 then begin 32 #define MB_ICONEXCLAMATION// Roda opção 02 48 #define MB_ICONASTERISKresult:=-1; end;end;exports ExecInClientDLL;beginend.//============================================================// ROTINA EM AdvPL PARA CHAMADA DA DLL//============================================================64 User Function DllTeste() Local hHdl := 0,buffer := "",xRet1 := 0 // AbreDllhHdl Dll hHdl := ExecInDLLOpen( "TSTDLL DllTeste.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 da ExecInDllRun..." xRet1 := ExecInDllRun( hHdl, 1,@buffer buffer )alert MessageBox("Retorno daExecInDllRun ExeDllRun: " + xRet1, "ExeDllRun", MB_ICONEXCLAMATION) //ExeDllRun2 ExecInDllRun retorna valor numérico daDLLbuffer DLL buffer:= "Executando a partir daExeDllRun2 ExeDllRun..."nRet2 xRet2 :=ExeDllRun2 ExecInDllRun( hHdl,1 2, @buffer )alert MessageBox("Retorno daExeDllRun2 ExeDllRun: " +StrZero(nRet2,3)) xRet2, "ExeDllRun", MB_ICONEXCLAMATION) //ExeDllRun3 ExecInDllRun retorna valor numérico daDLLbuffer DLL buffer:= "Executando a partir daExeDllRun3 ExeDllRun..."nRet3 xRet3 :=ExeDllRun3 ExecInDllRun( hHdl,1 3, @buffer )alert MessageBox("Retorno daExeDllRun3 ExeDllRun: " +StrZero(nRet3,3)) xRet3, "ExeDllRun", MB_ICONEXCLAMATION) // ---------------------------------------------------------------- // Fecha aDLLExecInDllClose DLL ExecInDllClose( hHdl ) Microsiga Protheus 8.11 , TOTVS Application Server 10 , ByYou Application Server
Return
|