BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

mmsystem.playsound in DLL initialization

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Multimedia
View previous topic :: View next topic  
Author Message
Xoff
Guest





PostPosted: Thu Aug 17, 2006 12:39 am    Post subject: mmsystem.playsound in DLL initialization Reply with quote



Hi,

I have a delphi (d2006) unit that calls mmsystem.playsound in its initialization block. I can use that unit in a simple project. However, if I make the same call in the initialization of a DLL (versus just a unit), and reference that DLL in my simple project, the program just hangs.


Has anybody experience/advice with that?
Thanks,
Xoff


Here is the code of the DLL:


library dllProject1;
uses
SysUtils,
Classes, MMSystem;
{$R *.res}


procedure testSound; stdcall;
begin
MMSystem.PlaySound('Minimize', 0, SND_ALIAS or SND_ASYNC or
SND_NODEFAULT or SND_NOWAIT);
end;


exports testSound;


begin
MMSystem.PlaySound('Minimize', 0, SND_ALIAS or SND_ASYNC or
SND_NODEFAULT or SND_NOWAIT);
end.


----------------------------------------------------------------
and the main program:
unit Unit1;


interface


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


type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;


procedure testSound; stdcall; external 'dllproject1.DLL';


var
Form1: TForm1;


implementation


{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
begin
testSound;
end;


initialization
//testSound;
end.

(and thanks to Riki Wiki for instructions on how to post here)
Back to top
Guest






PostPosted: Tue Aug 22, 2006 8:11 am    Post subject: Re: mmsystem.playsound in DLL initialization Reply with quote



It is never a good idea to have code executed in the initialization section when working with a DLL: not for nothing it is a dynamic link LIBRARY.
You should explicitly call the function after loading the dll or call a specific initialize method for the dll
Back to top
Xoff
Guest





PostPosted: Tue Aug 22, 2006 10:16 pm    Post subject: Re: mmsystem.playsound in DLL initialization Reply with quote



Thanks Thaddy,

I have simplified the issue to its root cause. However, my issue is a little more complex: I have a third party unit that makes that call in the unit initializtion. This by itself is Ok. But I use that unit in the DLL I am writing, so the call to mmsystem is made then and I have little control over it.

I have access to the source of that third party unit, but I would like to avoid making such changes, as I may forget when I get a new version.

I will contact the vendor of that unit, but I was wondering if there was something special about that call or mmsystem in general. Or is it a Delphi thing?

Xoff
<thaddy@.not.thaddy.com> wrote:
Quote:

It is never a good idea to have code executed in the initialization section when working with a DLL: not for nothing it is a dynamic link LIBRARY.
You should explicitly call the function after loading the dll or call a specific initialize method for the dll

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.