Ver Mensaje Individual
  #6  
Antiguo 06-10-2019
Diego E. Diego E. is offline
Miembro
 
Registrado: mar 2018
Posts: 30
Reputación: 0
Diego E. Va por buen camino
Cita:
Empezado por Neftali [Germán.Estévez] Ver Mensaje

Código Delphi [-]
function sspSendCommand (cmd:SSP_COMMAND; sspInfo:SSP_COMMAND_INFO):Integer; stdcall; external 'itlsspproc.dll';

Hola de nuevo, tengo algunas dudas más específicas acerca de este tema:

Tengo entendido que hay dos formas de usar las funciones dentro de la DLL(estática y dinámica), cuando intento llevar a cabo las siguientes lineas de C++ usando el dinámico tengo algo así:

Codigo de C++ a replicar(no tal cual, sólo lo que ocupo):
Código:
HINSTANCE hInst = LoadLibrary("ITLSSPProc.dll");
	if (hInst != NULL)
	{
		// Link function names

		// Opens the COM port
		OpenPort = (LPFNDLLFUNC1)GetProcAddress(hInst, "OpenSSPComPortUSB");
		if (OpenPort == NULL)
		{
			FreeLibrary(hInst);
			THREAD_UNLOCK
			return false;
		}
Yo hago algo así:
Código Delphi [-]
hInst := LoadLibrary('ITLSSPProc.dll');

    if hInst <> 0 then
    begin

      OpenPort := GetProcAddress(hInst, 'OpenSSPComPortUSB');
      if @OpenPort = nil then //Linea de la duda
      begin
        FreeLibrary(hInst);
        ShowMessage('No se pudo traer el OpenPort');
        Exit;
      end;

Pero aqui hay dos cosas, si en la línea de la duda pogo el @(que tengo entendido que es como usar un apuntador, pero no se) al evaluarlo me da nil (cosa que no debería pasar si funciona bien la linea del GetProcAddess), si le quito el arroba ni siquiera compila y me arroja el mensaje "Not enough actual parameters" que si no me equivoco es por que está intentando ejecutar la función(Cosa que no trato de hacer, yo sólo quiero saber si el GetProcAddess funcionó).

¿Saben que estoy haciendo mal o cual sería forma correcta de hacer el GetProcAddress?

El código completo es:
Código Delphi [-]
unit LibDLL;

interface

uses
  Vcl.Dialogs, SysUtils, Variants, Classes, Db, Forms, IniFiles, ADODB, Buttons,
  Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Controls, Windows;


Type

TSSP_FULL_KEY = record
  FixedKey: LongInt;
  EncryptKey: LongInt;
end {SSP_FULL_KEY};

SSP_PACKET = record
  packetTime: Word;
  PacketLength: Byte;
  PacketData: Array[0..255-1] of Byte;
end {SSP_PACKET};

TSSP_COMMAND = record
  Key: TSSP_FULL_KEY;
  BaudRate: LongInt;
  Timeout: LongInt;
  PortNumber: Byte;
  SSPAddress: Byte;
  RetryLevel: Byte;
  EncryptionStatus: Byte;
  CommandDataLength: Byte;
  CommandData: Array[0..255-1] of Byte;
  ResponseStatus: Byte;
  ResponseDataLength: Byte;
  ResponseData: Array[0..255-1] of Byte;
  IgnoreError: Byte;
end {SSP_COMMAND};

TSSP_KEYS = Record
  Generator: int64;
  Modulus: int64;
  HostInter: int64;
  HostRandom: int64;
  SlaveInterKey: int64;
  SlaveRandom: int64;
  KeyHost: int64;
  KeySlave: int64;
End;

TSSP_COMMAND_INFO = record
  CommandName: PByte;
  LogFileName: PByte;
  Encrypted: Byte;
  Transmit: SSP_PACKET;
  Receive: SSP_PACKET;
  PreEncryptTransmit: SSP_PACKET;
  PreEncryptRecieve: SSP_PACKET;
end {SSP_COMMAND_INFO};

TPORT_CONFIG = Record
  NumberOfPorts: String;
  LogFileName: PChar;
  Encrypted: String;
End;

type
  TOpenPort = function (cmd: TSSP_COMMAND): Integer;
//  function OpenPort (cmd: TSSP_COMMAND): Integer; cdecl; external 'ITLSSPProc.dll';
  function SSPSendCommand (cmd:TSSP_COMMAND; sspInfo:TSSP_COMMAND_INFO):Integer; stdcall; external 'ITLSSPProc.dll';


  Function VerificarDLL(): Boolean;
  Procedure InitConfSPO();
  Procedure InitialiseLibrary();


var
  cmd: TSSP_COMMAND;
  keys: TSSP_KEYS;
  sspKey: TSSP_FULL_KEY;
  info: TSSP_COMMAND_INFO;

  OpenPort: function (cmd: TSSP_COMMAND): Integer; stdcall;

  hInst: THandle;

implementation

//------------------------------------------------------------------------------

Function VerificarDLL(): Boolean;
var
  fileName:String;

begin

  Result := False;
  fileName := 'ITLSSPProc.dll';

  if fileexists(fileName) then
  begin
    Result := True;
  end
  else ShowMessage(fileName+' does not exist');

end;

//------------------------------------------------------------------------------

Procedure InitConfSPO();
begin

  InitialiseLibrary

end;

Procedure InitialiseLibrary();
begin

  if VerificarDLL then
  begin

    hInst := LoadLibrary('ITLSSPProc.dll');

    if hInst <> 0 then
    begin

      OpenPort := GetProcAddress(hInst, 'OpenSSPComPortUSB');
      if OpenPort = nil then
      begin
        FreeLibrary(hInst);
        ShowMessage('No se pudo traer el OpenPort');
        Exit;
      end;

    end
    else ShowMEssage('No se pudo instanciar la DLL');

  end;

end;


end.

He intentado con diferentes combinaciones(estáticas y dinámicas) pero no funciona, ahora estoy tratando de apegarme lo más posible a la forma C++ que coloqué.

¿Alguna idea? Si requieren el código y archivos que estoy tratando de usar se los puedo enviar por e-mail
Responder Con Cita