Erro ao carregar Dll dinamica ?
09/03/2010
0
Pessoal usei as funcao seguintes para executar a leituraX da dll de forma dinamica
+ quando chegar na de executar da um erro de memoria, o que pode estar errado
obrigado a tds
Declaracao
public
xDaruma_FI_LeituraX : function :Integer; StdCall ; implementation
function FunctionDetect (LibName, FuncName: String; var LibPointer: Pointer): boolean;
Var
LibHandle: tHandle;
begin
Result := false;
LibPointer := NIL;
{$IFDEF FPC}
LibHandle := dynlibs.LoadLibrary(LibName) ;
{$ELSE}
if LoadLibrary(PChar(LibName)) = 0 then
exit; { não consegiu ler a DLL }
LibHandle := GetModuleHandle(PChar(LibName)); { Pega o handle da DLL }
{$ENDIF} if LibHandle <> 0 then { Se 0 não pegou o Handle, falhou }
begin
LibPointer := GetProcAddress(LibHandle, PChar(FuncName));{Procura a função}
if LibPointer <> NIL then
Result := true;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
Var
FuncName: String;
LibPointer: Pointer;
iRetorno : Integer ;
begin
LibPointer:=@xDaruma_FI_LeituraX ;
FuncName:='Daruma_FI_LeituraX' ;
if not Assigned( LibPointer ) then
begin
if not FunctionDetect( cLIB_Daruma, FuncName, LibPointer) then
begin
LibPointer := NIL ;
ShowMessage( 'Erro ao carregar a função:'+FuncName+' de: '+cLIB_Daruma ) ;
end ;
end ;
iRetorno := xDaruma_FI_LeituraX ;
if ( iRetorno = 0) then
ShowMessage( 'Erro de execução!' ) ;
end;
xDaruma_FI_LeituraX : function :Integer; StdCall ; implementation
function FunctionDetect (LibName, FuncName: String; var LibPointer: Pointer): boolean;
Var
LibHandle: tHandle;
begin
Result := false;
LibPointer := NIL;
{$IFDEF FPC}
LibHandle := dynlibs.LoadLibrary(LibName) ;
{$ELSE}
if LoadLibrary(PChar(LibName)) = 0 then
exit; { não consegiu ler a DLL }
LibHandle := GetModuleHandle(PChar(LibName)); { Pega o handle da DLL }
{$ENDIF} if LibHandle <> 0 then { Se 0 não pegou o Handle, falhou }
begin
LibPointer := GetProcAddress(LibHandle, PChar(FuncName));{Procura a função}
if LibPointer <> NIL then
Result := true;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
Var
FuncName: String;
LibPointer: Pointer;
iRetorno : Integer ;
begin
LibPointer:=@xDaruma_FI_LeituraX ;
FuncName:='Daruma_FI_LeituraX' ;
if not Assigned( LibPointer ) then
begin
if not FunctionDetect( cLIB_Daruma, FuncName, LibPointer) then
begin
LibPointer := NIL ;
ShowMessage( 'Erro ao carregar a função:'+FuncName+' de: '+cLIB_Daruma ) ;
end ;
end ;
iRetorno := xDaruma_FI_LeituraX ;
if ( iRetorno = 0) then
ShowMessage( 'Erro de execução!' ) ;
end;
Emerson Charles
Curtir tópico
+ 0
Responder
Posts
09/03/2010
Devmedia Cursos
Vamos la.
Está utilizando a dll da daruma? se sim qual versão.
Sua impressora é fiscal ou não fiscal?
Qual erro gerado?
Lembrando que a própria daruma não da suporte a antigas DLL, o ideal é você utilizar o Darumaframework, que também é uma DLL, mas como milhões de recursos, onde basicamente você trabalha com TAGS para abrir gaveta, imprimir e todas rotinas básicas.
Abs
Está utilizando a dll da daruma? se sim qual versão.
Sua impressora é fiscal ou não fiscal?
Qual erro gerado?
Lembrando que a própria daruma não da suporte a antigas DLL, o ideal é você utilizar o Darumaframework, que também é uma DLL, mas como milhões de recursos, onde basicamente você trabalha com TAGS para abrir gaveta, imprimir e todas rotinas básicas.
Abs
Responder
Clique aqui para fazer login e interagir na Comunidade :)