PDA

Ver la Versión Completa : dll con forms


Rafa
03-02-2004, 20:09:54
saludos

Disculpen la insistencia pero no logro hacer qe me funcione el llamar un dll qe contiene forms.


Segui este Hilo (http://www.clubdelphi.com/foros/showthread.php?t=6357&highlight=DLL%2A) que me paso cadetill, pero me arroja este error

CoInitialize has not been called

y de ahi no paso
Ojala me puedan hechar la mano

__cadetill
03-02-2004, 20:30:41
Estaría bien que enviaras el código de llamada a la dll y la función/procedimiento de la dll para ver por donde puede ir el error.

delphi.com.ar
03-02-2004, 21:58:57
CoInitialize has not been called
Prueba poniendo un Application.Initialize antes del Application.Run

Saludos!

Rafa
04-02-2004, 01:30:07
Aqui va el codigo de como llamo a mi dll


procedure TForm1.FormCreate(Sender: TObject);
var
h:THandle;
setAdo:function (cCia: pchar;hwd:Integer):integer;stdcall;
Cia: pchar;
begin
h:=LoadLibrary('prueba.dll');
if h = 0 then
begin
showmessage('no se encontro prueba.dll');
exit;
end;
@setAdo:=GetProcAddress(h,'SetAdo');
if @setAdo=nil then
begin
showmessage('no se encontro SetAdo');
exit;
end;
getmem(Cia,3);
strlcopy(Cia,pchar('COI'),3);
setAdo(Cia,self.Handle);
FreeLibrary(h);
Application.Terminate;
end;

y este es el codigo de la dll


library prueba;
uses
SysUtils,
Classes,
Forms,
Dialogs,
ShellApi,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}
function SetAdo(Cia: pchar;hwd:Integer):integer;stdcall;
begin
Application.handle:=hwd;
try
Form1:=TForm1.Create(Application);
Form1.cCia:=Cia;
Showmessage(Form1.ADOStoredProc1.ConnectionString);
except
on E: Exception do
begin
ShowMessage('Error Creant Formulari. ' + E.Message);
result:=0;
raise;
exit;
end;
end;
result:=1;

end;

exports SetAdo;
begin

end.

__cadetill
04-02-2004, 10:00:44
Pues no sabría decirte, acabo de probar el código que mandas y no me ha dado ningún error :confused:

Mira lo que te comenta el amigo delphi.com.ar (aunque también lo he probado y ma ha funcionado bien :( )

delphi.com.ar
04-02-2004, 14:25:32
Si trabajas con ADO, te recomiendo probar lo que te he sugerido anteriormente.

Saludos!

Rafa
04-02-2004, 17:08:53
Me dices qe ponga application.initialize ,donde??
antes del application.run, pero si cuando haces una aplicacion delphi lo pone solo en el archivo del proyecto
program Pruebadll;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin


Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;

end

O a la mejor no te estoy entendiendo, es ahi no?

Gydba
04-02-2004, 17:47:31
Encontré este texto por inet, en una de esas te aclara algo:

From the readme.txt with Delphi 4

"COM/ActiveX initialization
--------------------------
The placement of COM/ActiveX initialization in Delphi
has changed in this version. Prior versions initialized
COM (through CoInitialize) in the initialization
section of the ComObj unit. COM initialization is now
accomplished during the call to Application.Initialize.
Therefore, COM applications that do not call
Application.Initialize must be changed so that it is
called prior to any calls to COM runtime or interface
methods. Likewise, calls to COM functions or interface
methods in unit initialization sections must be changed
to hook into Application.Initialize. This is only
necessary in .exe projects, not .DLL (library)
projects."

Tendrías que probar algo como:

try
CoInitialize(nil)
Application.Initialize;
...
Application.Run;
finally
CoUnInitialize;
end;


Nada de esto lo probé porque no tengo delphi donde estoy :(

delphi.com.ar
04-02-2004, 18:12:46
Me dices qe ponga application.initialize ,donde??
antes del application.run, pero si cuando haces una aplicacion delphi lo pone solo en el archivo del proyecto
program Pruebadll;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end

O a la mejor no te estoy entendiendo, es ahi no?
Si es ahí, pero nadie dice que lo que pone solo el IDE no lo puedas quitar... ¿No lo has quitado de tu proyecto?

Rafa
04-02-2004, 20:15:56
Pues no, no lo he quitado de mi proyecto,esta exactamente como lo ves en mi mensaje anterior, por eso se me hizo raro qe sugirieras el Application.initialize, pense qe habia qe ponerlo en otro lado.

Y lo del CoInitialize tmb lo lei en la ayuda de delphi, lo quise usar pero no compila, me marca como identificador no declarado.

Tal vez hay qe poner el uses correcto pero no se cual es, en la ayuda no le encontre cual era

:(

mamaro
15-02-2005, 20:43:11
Saludos... yo tengo un problema similar, utilizo DLLs para crear paneles que luego incrusto en un ejecutable que hace de base; me daba un problema por el estilo y encontré por ahí un documento que dice así:

OLE Error: CoInitialize has not been called

In a project that needed to display HTML documents, I decided to use the TWebBrowser control. I had used this handy ActiveX control successfully in other projects before.

This application was an MDI application, written in Delphi 5. As a 'specialty' I had installed a beta version of Internet Explorer on my system. I am not sure which of this is responsible for it, but when I would call the function in my application to display the HTML document, the TWebBrowser element could not be instantiated.
Instead I would receive an error message:

'CoInitialize has not been called'

The surprising thing is that the webbrowser control shows fine in design mode! I checked and TWebBrowser was properly installed. The underlieing DLL was also registered properly. A call of

regsvr32 shdocvw.dll

did not help. Finally I manually called the CoInitialize() function. I had to add OLE2 to the list of used units. A good place to do this is the initialization part as the sample snippet below shows.
Thanks to Martin Vreeken for pointing out the necessary CoUninitialize() call.

Note:
In a multithreaded application, you have to put a call to CoInitialize at the beginning of your thread's Execute method and a matching CoUnInitialize at its end.

uses

ActiveX, // <-- make sure to include this unit

// older Delphi versions use: OLE2 instead

Windows; // and others



initialization

CoInitialize(nil); // <-- manually call CoInitialize()

finalization

CoUnInitialize; // <-- free memory

end.

El tema es que las dos secciones finales (initialization y finalization) no se pueden incluir en una DLL, espero les ayude y me puedan ayudar a mi también, desde ya muchas gracias.:D