Acessando DLL de outras linguagens
Olá pessoal :wink: ! Tenho uma dúvida quanto à utilização de DLLs.
Só é possível utilizar uma DLL na mesma linguagem em que ela foi compilada? Digo isso porque tenho uma DLL feita em C++ e estou tentando utilizá-la em Delphi.
Além disso, existem alguns parâmetros nas funções da DLL inexistentes em Delphi. É possível fazer com que o Delphi leia estas funções?
Té +
Só é possível utilizar uma DLL na mesma linguagem em que ela foi compilada? Digo isso porque tenho uma DLL feita em C++ e estou tentando utilizá-la em Delphi.
Além disso, existem alguns parâmetros nas funções da DLL inexistentes em Delphi. É possível fazer com que o Delphi leia estas funções?
Té +
Dan.sm
Curtidas 0
Respostas
Fórum Vini
13/12/2003
A vantagem do uso de DLLs é justamente essa: utilizar uma dll criada em qualquer linguagem que as suporte.
Quanto aos parâmetros (não tenho certeza) acho que podem ser substituídos por tipos do Windows, mas convém que você mostre o protótipo da função. :D
Espero ter ajudado.
Vinicius.
Quanto aos parâmetros (não tenho certeza) acho que podem ser substituídos por tipos do Windows, mas convém que você mostre o protótipo da função. :D
Espero ter ajudado.
Vinicius.
GOSTEI 0
Dan.sm
13/12/2003
O protótipo da função é:
E o tipo FPService que aparece como argumento é a seguinte estrutura:
É possível traduzir esta estrutura para Delphi?
BYTE MoviLink(FPSERVICE pServ)
E o tipo FPService que aparece como argumento é a seguinte estrutura:
typedef struct tagSERVICE
{
unsigned char bService, //service to execute
fShortCnf; //short confirmation enable
unsigned short wTargetAddress; //target address or PC-interface
unsigned short wIndex, //Parameter-Index
wDataLength; //Anzahl PD bei READ..., WRITE.. bzw. Nutzdaten bei SCOPE
unsigned char bTeleType; //0:zykl. sonst: azyklische Telegramme
union
{
long lDate; //Standard-READ, WRITE-Dienst
unsigned char abData[10]; //abData[0]:Kanal-Nr. bei GET_SCOPE
}Data; //abData[1]:Block-Nr. bei GET_SCOPE
unsigned short awPA[10], //zu sendende Prozessdaten
awPE[10]; //empfangene Prozessdaten
unsigned char far* fpbDataPointer;
unsigned char abReserve[10];
ERRORMSG Error;
}SERVICE, far* FPSERVICE;
É possível traduzir esta estrutura para Delphi?
GOSTEI 0
Beppe
13/12/2003
type Long = Longint; PService = ^TService; TService = record bService, fShortCnf: Byte; wTargetAddress: Word; wIndex, wDataLength: Word; bTeleType: Byte; Data: record case Integer of lDate: Long; abData: array[0..9] of Byte; end; awPA, awPE: array[0..9] of Word; fpbDataPointer: PChar; abReserve: array[0..9] of Byte; Error: ERRORMSG; end; function MoviLink(pServ: PService): Byte; external ´MinhaLib.dll´ name ´MoviLink´;
Só por paranóia, cheque se a estrutura tem o mesmo tamnho em C e em Delphi.
Nota: Eu traduzi [b:40c18d5f17]unsigned char[/b:40c18d5f17] como Byte. Onde você usar caracteres mude para Char. Se o tipo [b:40c18d5f17]long[/b:40c18d5f17] é 8 bytes, então mude-o para Int64. É necessário o nome correto da função ao importá-la. Talvez seja necessário usar [b:40c18d5f17]extern[/b:40c18d5f17] [color=blue:40c18d5f17]´C´[/color:40c18d5f17].
GOSTEI 0
Fórum Vini
13/12/2003
Caro Ataliba,
somente uma pequena correção:
Você esqueceu do end do case:
Espero ter ajudado.
Vinicius.
somente uma pequena correção:
Você esqueceu do end do case:
type Long = Longint; PService = ^TService; TService = record bService, fShortCnf: Byte; wTargetAddress: Word; wIndex, wDataLength: Word; bTeleType: Byte; Data: record case Integer of lDate: Long; abData: array[0..9] of Byte; end; end; awPA, awPE: array[0..9] of Word; fpbDataPointer: PChar; abReserve: array[0..9] of Byte; Error: ERRORMSG; end; function MoviLink(pServ: PService): Byte; external ´MinhaLib.dll´ name ´MoviLink´;
Espero ter ajudado.
Vinicius.
GOSTEI 0
Dan.sm
13/12/2003
Valeu Ataliba pela ajuda! :D :wink:
GOSTEI 0
Fistsoft-sistemas Empresarial-ltda;
13/12/2003
Pessoal trabalho com c# estou tentando utilizar a dll movilink.dll mas fazer uma comunicação com o movidrive b mas não estou conseguindo. alguém ai sabe como utilizar esta dll?
Obrigado.
Obrigado.
GOSTEI 0