Ver Mensaje Individual
  #9  
Antiguo 27-09-2013
JXJ JXJ is offline
Miembro
 
Registrado: abr 2005
Posts: 2.475
Reputación: 22
JXJ Va por buen camino
con este codigo c
logre llamar a la funcionde la dll sin errores de memoria

Código:
 
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "consumedelphidllu.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
Tconsumedelphidllf *consumedelphidllf;
//---------------------------------------------------------------------------
__fastcall Tconsumedelphidllf::Tconsumedelphidllf(TComponent* Owner)
        : TForm(Owner)
{
}

typedef const char* __cdecl(*pFunc)(char*); pFunc Directorio;
//---------------------------------------------------------------------------
void __fastcall Tconsumedelphidllf::Button1Click(TObject *Sender)
{
 HINSTANCE hDll ;

  hDll = LoadLibrary("directorios.dll");
  __try {
    if(hDll) {
      Directorio = (pFunc)GetProcAddress(hDll, "Directorio"); //obtiene el puntero
      Edit1->Text =  Directorio("DirUserDocs"); // ( lalalala )
    } else
      ShowMessage("No se pudo cargar la DLL");
  }
  __finally {
    FreeLibrary(hDll);
  }


 

}
//---------------------------------------------------------------------------
ahora el problema es el codigo delphi
por que al llamar a la funcion
que busca el directorio
al pasar el resultado en el programa borland c no da error sino que se pone en blaco el edit.
pero si se muestra el mesagebox con el directorio esperado.

Código Delphi [-]
library directorios;

uses
  EMemLeaks,
  EResLeaks,
  EDialogWinAPIMSClassic,
  EDialogWinAPIEurekaLogDetailed,
  EDialogWinAPIStepsToReproduce,
  EDebugExports,
  ExceptionLog7,
  SHFolder,

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,
     ActiveX, shlobj, ShellAPI,   Registry, IniFiles;

 
    
{$R *.res}
function GetSystemPath(Folder: integer): PChar;
var sDir: string;
begin
  SetLength(sDir, MAX_PATH);
  ZeroMemory(@sDir[1], MAX_PATH);
  if Succeeded(SHGetFolderPath(0, Folder, 0, 0, PAnsiChar(sDir))) then
  begin
   Result := PChar(sDir);
    ShowMessage(sDir);
    end;
end;

function Directorio(dir: string): PChar; stdcall;
begin
 Result :=  GetSystemPath(CSIDL_PERSONAL);
end;


exports
Directorio;



begin
end.

ya no se donde esta el problema..
gracias por su tiempo.

ustedes no tienen algunos codigos fuente de los cuales aprender sobre
dll con delphi y llamado con c++, y dll c con llamados por programa c.c++

sigo revisando que ando haciendo mal.
Responder Con Cita