🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #12918

Re: Windows message question

#12918
From: Remy Lebeau (TeamB)
Date: Thu, 06 Nov 2003 09:27
47 lines
3568 bytes
"Martin C" <martinc@aol.com> wrote in message
news:3fa2df07@newsgroups.borland.com...

> My only problem here that the dll send these messages to my
> exe while processing other functions, and once the dll message is
> received by the exe, the dll project holds all its running operations
> until all the code under my exe message event finish executing,

Correct.  Especially since you are apparenty using WM_COPYDATA, which *must*
be called via SendMessage(), never PostMessage().  SendMessage() waits until
the message is processed, whereas PostMessage() does not.  This is critical
particular when passing pointers around, to ensure that the passed memory is
still valid by the time the message is eventually processed.

> so is it possible by anyway not to keep the dll wait until all the
> code under my exe message event finish executing.

Only if you dynamically allocate the memory for the string each time, and
then pass the new pointer as a message parameter.  Then you can use
PostMessage() instead of SendMessage() (but not for the WM_COPYDATA
message).  Thus the application could then receive the string when
appropriate without blocking the DLL, the string memory would remain valid
regardless of anything the DLL is doing after sending the message, and the
application would then be responsible for freeing the string after it
receives it.

However, then you get into the issue of mixing memory managers between the
DLL and application.  It is not good design to allocate memory in the DLL
and then make the application free it directly (and vice versa).  Usually,
they will be using different memory managers, and it is not safe to
deallocate memory from one manager that was allocated in another.  Each
manager has its own unique way of managing memory, and frequently include
additional data in allocated memory which it uses later to ensure proper
deallocation of the memory.  In this case, you would then need to export an
additional function from the DLL which the application can call when needed
to free the string memory that was allocated for the message.  That way, the
string memory will be allocate and deallocated by the same memory manager
and no problems arrise.

Alternatively, just have the DLL spawn a separate thread for the purpose of
waiting for the message processing, then you can use SendMessage() without
extra allocation issues, while not blocking the DLL from doing other things
while waiting for the message to be processed.


Gambit
Technical Details
Message-ID: <3faa132d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3f9e672d@newsgroups.borland.com> <3f9ea71e$1@newsgroups.borland.com> <3f9eaa27@newsgroups.borland.com> <3f9eb458$1@newsgroups.borland.com> <3fa2df07@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,8012e723bc3abeb
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-11-06 01:25:45 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f9e672d@newsgroups.borland.com> <3f9ea71e$1@newsgroups.borland.com> <3f9eaa27@newsgroups.borland.com> <3f9eb458$1@newsgroups.borland.com> <3fa2df07@newsgroups.borland.com>
Subject: Re: Windows message question
Date: Thu, 6 Nov 2003 01:27:06 -0800
Lines: 49
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.137.149
Message-ID: <3faa132d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1068110637 67.22.137.149 (6 Nov 2003 01:23:57 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail