Ver Mensaje Individual
  #1  
Antiguo 28-03-2022
Avatar de cesarsoftware
cesarsoftware cesarsoftware is offline
Miembro
 
Registrado: nov 2006
Posts: 241
Reputación: 18
cesarsoftware Va por buen camino
Smile Funcion en DLL pasar de C++ a Delphi

Hola compañeros.
Estoy tratando de trasladar un codigo escrito en C++ que llama a funciones de una DLL a Delphi. El procedimiento basico esta hecho pero no comprendo o no se bien como pasar los parametros,
Escribo el codigo C++
Código:
struct MELDEVICEDATA
DWORD dwDeviceType; /* Device type (Set DEVICETYPE_TCP.) */
APIDEVICE uniDeviceInfo; /* Device information */

struct APIDEVICE
struct Tcp
char IPAddr[16]; /* IP address (e.g. “192.168.100.1”) */
long lPortNo; /* Port No. (Set 683 (fixed value).) */
char dummy[12]; /* Reserved */

DWORD WINAPI melIoctl( HWND hWnd, long lAddress, long lFunction, LPVOID lpData ); ): Longint; stdcall; /* function in DLL */

void setmachine; {
/* Set IP address */
MELDEVICEDATA MelIoctlData;
long lIPAdrLen;
char szIPAddress[] = "192.168.100.1";
DWORD dwStatus;
/* Set device type */
melIoctlData.dwDeviceType = DEVICETYPE_TCP;
/* Set IP address */
lIPAdrLen = strlen(szIPAddress);
strncpy(MelIoctlData.uniDeviceInfo.Tcp.IPAddr, szIPAddress, lIPAdrLen);
melIoctlData.uniDeviceInfo.Tcp.IPAddr[lIPAdrLen] = '\0';
/* Set port No. */
MelIoctlData.uniDeviceInfo.Tcp.lPortNo = 683;
dwStatus = melIoctl(NULL, ADR_MACHINE(1), DEV_SET_COMMADDRESS, &MelIoctlData);
}
Y ahora el codigo Delphi que casi seguro no esta bien.
Código Delphi [-]
type APIDEVICE = record
  IPAddr: ansistring;             // IP address (e.g. “192.168.100.1”)
  lPortNo: word;                  // Port No. (Set 683 (fixed value).)
  dummy: array[0..11] of UINT16;  // array of supported bus controllers
end;

type MELDEVICEDATA = packed record
  dwDeviceType: LongWord;         // Device type (Set DEVICETYPE_TCP.)
  uniDeviceInfo: APIDEVICE;       // Device information
end;

type tMELDEVICEDATA = ^MELDEVICEDATA;

function melIoctl(HWND, lAddress, lFunction: LongWord; lpData: Pointer): LongWord; cdecl; stdcall; external 'ncap.iDLL';

procedure TForm1.BotonProbarClick(Sender: TObject);
var
  MelIoctlData: tMELDEVICEDATA;
  szIPAddress: ansistring;
  dwStatus: LongWord;
begin
  StaticText1.Caption := '';
  StaticText1.Update;
  New(MelIoctlData);
  szIPAddress := AnsiString(EditCncIP.Text);
  MelIoctlData^.dwDeviceType := DEVICETYPE_TCP;
  MelIoctlData^.uniDeviceInfo.IPAddr := szIPAddress;
  MelIoctlData^.uniDeviceInfo.lPortNo := 683;
  dwStatus := melIoctl(Self.Handle, ADR_MACHINE, DEV_SET_COMMADDRESS, tMELDEVICEDATA(MelIoctlData));
//  function melIoctl(HWND: LongWord; var lAddress, lFunction: LongWord; const lpData: string): Longint; stdcall;
  StaticText1.Caption := IntToStr(dwStatus);
  if dwStatus = ME_SYSFUNC_IOCTL_ADDR then // Address error
    Beep
  else
  if dwStatus = ME_SYSFUNC_IOCTL_FUNCTION then // Function error
    Beep
  else
    Beep;
  Dispose(tMELDEVICEDATA(MelIoctlData));
end;

Si alguien es tan amable de ayudarme, lo agradecere ampliamente, cervezas incluidas
__________________
Disfruta de la vida ahora, vas a estar muerto mucho tiempo.
Responder Con Cita