Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: HtmlViewer in dll form causes the main application to crash


This question is answered.


Permlink Replies: 6 - Last Post: Nov 16, 2014 1:24 PM Last Post By: Zsolt Németh
Zsolt Németh

Posts: 8
Registered: 8/6/14
HtmlViewer in dll form causes the main application to crash  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2014 3:08 AM
I have a dll form for viewing incoming emails. If I put HTMLViewer to this form, after calling the dll the main application crashes. But on the application form HTMLViewer works correctly. What can be the problem? How can I fix it?

Thanks,
Zsolt
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: HtmlViewer in dll form causes the main application to crash  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2014 4:43 AM   in response to: Zsolt Németh in response to: Zsolt Németh
Zsolt

I have a dll form for viewing incoming emails. If I put HTMLViewer to this form, after calling the dll the main application crashes. But on the application form HTMLViewer works correctly. What can be the problem? How can I fix it?

There is not a great deal of information there to allow anyone to assist you. I'm guessing that the dll is something you've written, if so then try debugging it. I can tell you how to do that in older Delphi's but I have no idea how anything after D2006 works so if you have a modern one then you'll have to figure it out yourself.

A few questions which may allow someone to peer into their crystal ball and help you.

1. What error message do you get?
2. Is the dll linked dynamically or statically?
3. If dynamically is the crash when you try and load the dll or when you call a function from within the dll?
4.. What else is in the dll and what happens when you call those?
5. Are the application and dll both 32 bit or both 64 bit?

Roy Lambert
Zsolt Németh

Posts: 8
Registered: 8/6/14
Re: HtmlViewer in dll form causes the main application to crash  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2014 5:18 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:
Zsolt

I have a dll form for viewing incoming emails. If I put HTMLViewer to this form, after calling the dll the main application crashes. But on the application form HTMLViewer works correctly. What can be the problem? How can I fix it?

There is not a great deal of information there to allow anyone to assist you. I'm guessing that the dll is something you've written, if so then try debugging it. I can tell you how to do that in older Delphi's but I have no idea how anything after D2006 works so if you have a modern one then you'll have to figure it out yourself.

A few questions which may allow someone to peer into their crystal ball and help you.

1. What error message do you get?
2. Is the dll linked dynamically or statically?
3. If dynamically is the crash when you try and load the dll or when you call a function from within the dll?
4.. What else is in the dll and what happens when you call those?
5. Are the application and dll both 32 bit or both 64 bit?

Roy Lambert

Sorry, some additional informations:

dynamic dll call and dll library (without some codes):

function ShowMail(ToAdress, Attach, Html, Body, ToList, Subj: String): Boolean;
type tShowMail=function(ToAdress, Attach, Html, Body, ToList, Subj: String): Boolean; stdcall;
var
  Handle: THandle;
  GoProc: tShowMail;
begin
try Handle := LoadLibrary('z_mail.dll'); Result:= False;
  if Handle<>0 then begin
    @GoProc := GetProcAddress(Handle, 'showmail');
    if @GoProc<>nil then Result:= GoProc(ToAdress, Attach, Html, Body, ToList, Subj);
    end
  else ShowMessage('Error: opening z_mail.dll');
  finally FreeLibrary(Handle);
  end
end;
 
library z_mail;
uses
  SysUtils,
  IdSMTP,
  Classes,
  uMail in 'uMail.pas' {fMail};
 
{$R *.res}
 
function showmail(ToAdress, Attach, HTML, Body, ToList, Subj: String):Boolean; export; stdcall;
begin
with tfMail.Create(fMail) do try
  ...
  ShowModal;
  ...
  finally Free;
  end;
end;
 
exports showmail;
 
begin
end.


On the fMail form is a tMemo and a HTMLViewer component (and some more). When I call this dll from main application, the form is open but after closing the main application does not get the focus. Delete HTMLViewer compoent and uses references everything is good. HtmlViewer component in the main application also good.

1. Does not error message, only the main application lost the focus
2. dll linked dynamically
3. Crash after closing dll
4. Only write the HTMLUn2, HtmlView unit into uses clause is enough to Trigger the event (without placing component to form). For test I switched off every relevant functions.
5. dll 32 bit, xe7

Zsolt Németh

Edited by: Zsolt Németh on Nov 11, 2014 5:37 AM

Perhaps this could be similar problem, but unfortunately I could not solve the problem in this way:
http://embarcadero.newsgroups.archived.at/public.delphi.language.delphi.win32/201008/1008229911.html

Edited by: Zsolt Németh on Nov 11, 2014 8:08 AM
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: HtmlViewer in dll form causes the main application to crash [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 15, 2014 1:29 AM   in response to: Zsolt Németh in response to: Zsolt Németh
Zsolt

Its a long time since I bothered with dlls (at least 15 years) so I'm well out of date but back then if you wanted to pass data around you had to use ShareMem, also I'm baffled by the functions where the parameters don't have any types declared.

I have no idea wether or not I would expect focus to return to the calling application or which part of it if it did return focus.

If there's a crash being caused by the unloading of the dll with just the HTMLViewer unit added but nothing called I would suspect a problem in a finalization section but there's

Roy Lambert

Andrew Baylis

Posts: 27
Registered: 7/19/00
Re: HtmlViewer in dll form causes the main application to crash [Edit]
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 15, 2014 1:41 PM   in response to: Zsolt Németh in response to: Zsolt Németh
On 12/11/2014 3:14 AM, Zsolt Németh wrote:
<snip>

Sorry, some additional informations:

dynamic dll call and dll library (without some codes):

{code}
function ShowMail(ToAdress, Attach, Html, Body, ToList, Subj: String): Boolean;
type tShowMail=function(ToAdress, Attach, Html, Body, ToList, Subj: String): Boolean; stdcall;
var
Handle: THandle;
GoProc: tShowMail;
begin
<snip>

Perhaps this could be similar problem, but unfortunately I could not solve the problem in this way:
http://embarcadero.newsgroups.archived.at/public.delphi.language.delphi.win32/201008/1008229911.html

Edited by: Zsolt Németh on Nov 11, 2014 8:08 AM
Passing Strings to DLLs is fraught with danger unless you are sharing
the memory manager. The expected way is to pass PChar values and let the
calling program deal with the memory.

You could try
function ShowMail(ToAdress, Attach, Html, Body, ToList, Subj: PChar):
Boolean; stdcall;

Cheers,
Andrew
Zsolt Németh

Posts: 8
Registered: 8/6/14
Re: HtmlViewer in dll form causes the main application to crash [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 16, 2014 1:24 PM   in response to: Andrew Baylis in response to: Andrew Baylis
Passing Strings to DLLs is fraught with danger unless you are sharing
the memory manager. The expected way is to pass PChar values and let the
calling program deal with the memory.

You could try
function ShowMail(ToAdress, Attach, Html, Body, ToList, Subj: PChar):
Boolean; stdcall;

Cheers,
Andrew

PChar variables solve the problem.

Last days I wasted my time searching different solutions. My big mistake was in my test environment I always used string variables (I have some other dlls with strings without problems). Probably the OLE objects in dll do not like string parameters, even with sharemem unit.

Thanks everyone for helping.
Alex Sv

Posts: 92
Registered: 1/11/04
Re: HtmlViewer in dll form causes the main application to crash  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2014 1:39 PM   in response to: Zsolt Németh in response to: Zsolt Németh
In case you do not solve the problem you may also look at http://delphihtmlcomponents.com/ - it works in DLL.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02