Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 11-05-2012
JXJ JXJ is offline
Miembro
 
Registrado: abr 2005
Posts: 2.475
Poder: 22
JXJ Va por buen camino
Question ¿como hacer dll c puro en bcb2010 y loader en delphi 2010?

hola estoy haciendo una dll
en c
c puro, no es cpp o c++
con el ide de c++ builder 2010

y el programa que lo consume esta hecho en delphi 2010

el problema es que no me devuelve lo que yo quiero un string para saber que paso con
las instrucciones

pongo el codigo. de la dll

Código:
// ---------------------------------------------------------------------------
// ES UNA DLL TIPOP C  SIN NINGUN ESTILO NI VCL NI ESTILO VC
// ---------------------------------------------------------------------------

#include <windows.h>
#include <string.h>
#pragma argsused
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

static char *file2string(FILE *file)
{
  char buffer[256];
  char *ptr;
  char *string=NULL;
  size_t len=0;
  size_t stringlen;

  if(file) {
    while(fgets(buffer, sizeof(buffer), file)) {
      ptr= strchr(buffer, '\r');
      if(ptr)
        *ptr=0;
      ptr= strchr(buffer, '\n');
      if(ptr)
        *ptr=0;
      stringlen=strlen(buffer);
      if(string)
        string = realloc(string, len+stringlen+1);
      else
        string = malloc(stringlen+1);

      strcpy(string+len, buffer);

      len+=stringlen;
    }
    return string;
  }
  else
    return NULL; /* no string */
}

static char *file2memory(FILE *file, long *size)
{
  char buffer[1024];
  char *string=NULL;
  char *newstring=NULL;
  size_t len=0;
  long stringlen=0;

  if(file) {
    while((len = fread(buffer, 1, sizeof(buffer), file))) {
      if(string) {
        newstring = realloc(string, len+stringlen);
        if(newstring)
          string = newstring;
        else
          break; /* no more strings attached! :-) */
      }
      else
        string = malloc(len);
      memcpy(&string[stringlen], buffer, len);
      stringlen+=len;
    }
    *size = stringlen;
    return string;
  }
  else
    return NULL; /* no string */
}


static size_t mywrite(void * ptr , size_t size , size_t nmemb , void * stream){
int ret  = fwrite(ptr,size,nmemb,(FILE *)stream);
fwrite(ptr,size,nmemb,stdout);
return ret;
}



char __declspec(dllexport)WINAPI   suma(char *ELPRIMERPARAMETRO, char *ELSEGUNDOPARAMETRO,
                                      char *ELTERCERPARAMETRO, char *ELCUARTOPARAMETRO)
{

      FILE * header = fopen(ELPRIMERPARAMETRO,"w");
      FILE * body = fopen(ELSEGUNDOPARAMETRO,"w");

 char *TipoResultado;
      TipoResultado = "3333";


   MessageBox( NULL, ELPRIMERPARAMETRO, "1r", MB_OK );
   MessageBox( NULL, ELSEGUNDOPARAMETRO, "2d", MB_OK );
   MessageBox( NULL, ELTERCERPARAMETRO, "3e", MB_OK );
   MessageBox( NULL, ELCUARTOPARAMETRO, "4t", MB_OK );

    return *TipoResultado;
}

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason,
    void* lpReserved)
    {
    return 1;
}
// ---------------------------------------------------------------------------
y este es el de l aaplicacion delphi
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExceptionLog;

type
    TDLLFunc = function(param1: AnsiString; param2: AnsiString; param3: AnsiString; param4: AnsiString): PAnsiChar;

type
  TForm1 = class(TForm)
    Button1: TButton;
    EurekaLog1: TEurekaLog;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

  { assign a nil - not loaded function }

  {assign a nil - not loaded function}
 const
   DLLFunc: TDLLFunc = nil;
   DLLName = 'inicio.DLL';
 {handle of loaded dll}
 var
  DLLHandle: THandle;

implementation

{$R *.dfm}
function suma(parametro1: AnsiString; parametro2: AnsiString; parametro3 :AnsiString;  parametro4 :AnsiString): PAnsiChar; stdcall; far; external 'inicio.DLL';

procedure TForm1.FormCreate(Sender: TObject);
var
  resultadosuma: PAnsiChar;
  recibido:string;
begin
  DLLHandle := LoadLibrary(DLLName);

  if (DLLHandle < HINSTANCE_ERROR) then
    raise Exception.Create(DLLName + ' library can not be loaded or not found. ' + SysErrorMessage(GetLastError));
  try
    @DLLFunc := GetProcAddress(DLLHandle, 'suma');
    if Assigned(DLLFunc) then
    begin

resultadosuma :=   suma(
                     PansiChar(AnsiString('a1')),
                     PansiChar(AnsiString('b2')),
                     PansiChar(AnsiString('c3')),
                     PansiChar(AnsiString('d4'))
                     );
    end;
  finally
    FreeLibrary(DLLHandle);
  end;

  ShowMessage(  resultadosuma);

end;

end.


logre que se pasen los parametros de delphi a la dll y que me los muestre
el problema es que no me devuelve nada
yo espero un string
3333
y no me vuelve nada

solo me ha funcionado usando integer en vez de string.
en la dll c

en c estoy aprendiendo. y pues no se que hago mal

gracias.


la funcion se llama suma. por que asi se me ocurrio pero debe de regresar un string para procesarlo
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Como instalo ZeosLib en Delphi 2010 jorosmtz Conexión con bases de datos 21 21-08-2012 00:48:46
delphi 2010 imagenes png¿como usarlas? JXJ Varios 2 13-09-2010 21:40:49
Hacer que Delphi 2010 luzca como Delphi 7 jorosmtz La Taberna 0 11-04-2010 22:45:36
¿cómo hacer un reporte con ravereport de delphi 2010 o un manual ? Master23 Impresión 1 06-04-2010 16:43:20
Iniciar un Loader REHome .NET 5 24-12-2008 10:24:29


La franja horaria es GMT +2. Ahora son las 10:44:39.


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
Copyright 1996-2007 Club Delphi