Acessando DLL de outras linguagens
13/12/2003
0
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
Posts
13/12/2003
Fórum Vini
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.
14/12/2003
Dan.sm
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?
14/12/2003
Beppe
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].
14/12/2003
Fórum Vini
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.
04/12/2012
Fistsoft-sistemas Empresarial-ltda;
Obrigado.
Clique aqui para fazer login e interagir na Comunidade :)