Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Error al Llamar Función en DLL (Interface not suported). (https://www.clubdelphi.com/foros/showthread.php?t=83419)

webmasterplc 16-06-2013 15:43:38

Error al Llamar Función en DLL (Interface not suported).
 
Buenas, estoy escribiendo una función para enviar datos post a un gateway de sms, ya hice la función y todo perfecto, pero ahora me gustaría tenerla en dll la paso a dll pero me dice Interface Not Suported, aqui dejo el codigo de la dll y la llamada.

Codigo DLL.

Código Delphi [-]
library sms;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes,
  IdHTTP;

{$R *.res}
function enviarSMS (url,usuario,clave,phone,mensaje : string) : string; export
var
  http: TIdHttp;
  params: TStrings;
  respuesta: string;
begin
    http := TIdHTTP.Create(nil);
    params := TStringList.Create;

    begin
        params.Add('usuario='+usuario);
        params.Add('clave='+clave);
        params.Add('telefonos='+phone);
        params.Add('texto='+mensaje);
        respuesta := http.Post(url, params);
    end;
    params.Free;
    http.Free;
end;
end.

este es el de la llamada

Código Delphi [-]
var
Form1: TForm1;
function enviarSMS (url,usuario,clave,phone,mensaje : string) : string; stdcall external'sms.dll';
implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin
enviarSMS(edt1.Text,edt2.Text,edt3.Text,edt4.Text,edt5.Text);
edt4.Clear;
edt5.Clear;
end;

beginner01 16-06-2013 22:01:37

Hola.

Es bueno especificar que versión de delphi usas.

Yo realicé una prueba con tu código en Delphi xe y lo primero es que no vi el error que comentas, pero lo primero que te puedo sugerir es que agregues la función a ejecutar desde fuera de la dll en una sección exports.


Código Delphi [-]
library sms;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes,
  IdHTTP;

{$R *.res}
function enviarSMS (url,usuario,clave,phone,mensaje : string) : string;
var
  http: TIdHttp;
  params: TStrings;
  respuesta: string;
begin
    http := TIdHTTP.Create(nil);
    params := TStringList.Create;

    begin
        params.Add('usuario='+usuario);
        params.Add('clave='+clave);
        params.Add('telefonos='+phone);
        params.Add('texto='+mensaje);
        respuesta := http.Post(url, params);
    end;
    params.Free;
    http.Free;
end;

exports 
 enviarSMS;


end.

beginner01 16-06-2013 22:11:45

Hola.

Te dejo un enlace que te puede servir de mucha ayuda, está en ingles, pero contiene una buena información de como realizar las
llamadas a las funciones contenidas en dll y las precauciones.

Calling Conventions.

Te sugiero, que te fijes en en el demo al final de la página del enlace.

webmasterplc 16-06-2013 22:14:53

Uso delphi 7, voy a probar lo que me dices y les comento

webmasterplc 17-06-2013 00:58:48

Gracias Funciona bien saludos


La franja horaria es GMT +2. Ahora son las 10:36:02.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi