<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Ross. <br>
How and where are you telling the DLL which window handle to post its
messages to? <br>
<br>
is there a dll call such as
SetWindowHandleformessaging(MyInstance.Handle) ? or does it just happen
like magic?<br>
<br>
Ross Levis wrote:
<blockquote cite="mid021101c57b18$dad7bb50$5100a8c0@levis4" type="cite">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta content="MSHTML 6.00.2900.2668" name="GENERATOR">
<div><font face="Arial" size="2">Hi Kyley</font></div>
<div> </div>
<div><font face="Arial" size="2">Yes, I do receive WM_USER messages.
This is how the DLL communicates. As I mentioned, it works perfectly
if I put all the message checking in the mainform, but it doesn't work
in the separate unit, even with the AllocateHWnd.</font></div>
<div> </div>
<div><font face="Arial" size="2">Here is all my relevant code.</font></div>
<div> </div>
<div><font color="#000080" face="Arial" size="2">TMyComponent =
class(TComponent)<br>
private<br>
FHandle: HWnd;<br>
procedure WndProc(var Message: TMessage);</font></div>
<div><font color="#000080" face="Arial" size="2">end;</font></div>
<div> </div>
<div><font color="#000080" face="Arial" size="2">constructor
TMyComponent.Create;<br>
begin<br>
inherited Create(AOwner);<br>
FHandle := AllocateHWnd(WndProc);<br>
end;</font></div>
<div> </div>
<div><font color="#000080" face="Arial" size="2">destructor
TMyComponent.Destroy;<br>
begin<br>
DeallocateHWnd(FHandle);<br>
inherited Destroy;<br>
end;</font></div>
<div> </div>
<div><font color="#000080" face="Arial" size="2">procedure
TMyComponent.WndProc(var Message: TMessage);<br>
begin<br>
with Message do<br>
if Msg = WM_USER then<br>
begin</font></div>
<div><font color="#000080" face="Arial" size="2"> Result := lparam
+ wparam //(for example)</font></div>
<div><font color="#000080" face="Arial" size="2"> end</font></div>
<div><font color="#000080" face="Arial" size="2"> else Result :=
DefWindowProc(FHandle, Msg, wParam, lParam);<br>
end;</font></div>
<div> </div>
<div><font face="Arial" size="2">I get a couple messages when the
program loads but I never get Msg = WM_USER.</font></div>
<div><font face="Arial" size="2">Do you see any problems with this
code?</font></div>
<div> </div>
<div><font face="Arial" size="2">The following code, however, when
placed in the mainform does detect WM_USER messages.</font></div>
<div> </div>
<div><font color="#000080" face="Arial" size="2">TForm1 = class(TForm)<br>
...</font></div>
<div><font color="#000080" face="Arial" size="2"> procedure
WMUSER(var Message: TMessage); message WM_USER;</font></div>
<div><font color="#000080" face="Arial" size="2">end;</font></div>
<div> </div>
<div><font color="#000080" face="Arial" size="2">procedure
TForm1.WMUSER(var Message: TMessage);<br>
begin<br>
with Message do<br>
if Msg = WM_USER then showmessage('It Works!');<br>
end;</font></div>
<div> </div>
<div><font face="Arial" size="2">I've tried different combinations of
the syntax, including the <font color="#000080">message WM_USER;</font><font
color="#000000"> bit in the unit but it doesn't make any difference at
all. In fact I still get other messages when the program starts.</font></font></div>
<div> </div>
<div><font face="Arial" size="2">Thanks for the help.</font></div>
<div><font face="Arial" size="2">Ross.</font></div>
<blockquote
style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div
style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">-----
Original Message ----- </div>
<div
style="background: rgb(228, 228, 228) none repeat scroll 0%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>From:</b>
<a title="KyleyHarris@gmail.com" href="mailto:KyleyHarris@gmail.com">Kyley
Harris</a> </div>
<div
style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>To:</b>
<a title="delphi@ns3.123.co.nz" href="mailto:delphi@ns3.123.co.nz">NZ
Borland Developers Group - Delphi List</a> </div>
<div
style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Sent:</b>
Monday, June 27, 2005 10:01 PM</div>
<div
style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Subject:</b>
[Spam] Re: [DUG] Intercepting messages in separate units</div>
<div><br>
</div>
Try the wrapper class just incase you have made a blooper. but it is
unlikely that you will ever receive a message with the ID WM_USER. that
is simply an offset to coordinate with windows messages. eg
WM_USERLOGON = WM_USER+1 is an example of a user defined message.<br>
<br>
then <br>
myobject = class(TObject)<br>
procedure WMUSERLOGON(var msg:TMessage);message WM_USERLOGON; <br>
end;<br>
<br>
the above procedure will only ever receive that one message. You need
to know exactly what messages you are expecting from the dll.<br>
<br>
if you use my wrapper, and attached an instance of the above object to
message handler it will route the messages to that instance..<br>
<br>
Ross Levis wrote:
<blockquote cite="mid019b01c57af5$e31e7f10$5100a8c0@levis4"
type="cite">
<meta content="MSHTML 6.00.2900.2668" name="GENERATOR">
<div><font face="Arial" size="2">Thanks for that Kyley. I
managed to implement AllocateHWnd etc, and everything appears correct
and logical. It's picking up some Windows messages but not the WM_USER
messages being sent. WM_USER is message number 1024. I'm getting
Message.Msg = 28 and that's about it.</font></div>
<div> </div>
<div><font face="Arial" size="2">I tried the same code in the
mainform as a test and this worked but only after I specified the
following:</font></div>
<div><font face="Arial" size="2">
<div><font face="Arial" size="2">procedure MyMessage(var Message:
TMessage); message WM_USER;</font></div>
<div> </div>
</font></div>
<div><font face="Arial" size="2">If I leave off "message
WM_USER", then nothing gets through to the procedure in the mainform at
all.</font></div>
<div> </div>
<div><font face="Arial" size="2">I tried this in the unit and it
doesn't make any difference. Message 28 is still getting to the
procedure and no 1024.</font></div>
<div> </div>
<div><font face="Arial" size="2">You can tell I'm no expert when
it comes to this. Do I need to use your fancy looking wrapper class?</font></div>
<div> </div>
<div><font face="Arial" size="2">I must be missing something.</font></div>
<div> </div>
<div><font face="Arial" size="2">Thanks,</font></div>
<div><font face="Arial" size="2">Ross.</font></div>
<blockquote
style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div
style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">-----
Original Message ----- </div>
<div
style="background: rgb(228, 228, 228) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>From:</b>
<a title="KyleyHarris@gmail.com"
href="mailto:KyleyHarris@gmail.com">Kyley Harris</a> </div>
<div
style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>To:</b>
<a title="delphi@ns3.123.co.nz"
href="mailto:delphi@ns3.123.co.nz">NZ Borland Developers Group -
Delphi List</a> </div>
<div
style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Sent:</b>
Monday, June 27, 2005 7:13 PM</div>
<div
style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Subject:</b>
[Spam] Re: [DUG] Intercepting messages in separate units</div>
<div><br>
</div>
in the forms unit<br>
<br>
function AllocateHWnd(Method: TWndMethod): HWND; deprecated; { moved
to Classes.pas }<br>
{$EXTERNALSYM AllocateHWnd}<br>
procedure DeallocateHWnd(Wnd: HWND); deprecated; { moved
to Classes.pas }<br>
<br>
<br>
read the help will sort you out just fine<br>
<br>
Ross Levis wrote:
<blockquote cite="mid014401c57ae7$48177ca0$5100a8c0@levis4"
type="cite">
<meta content="MSHTML 6.00.2900.2668" name="GENERATOR">
<style></style>
<div><font face="Arial" size="2">I'm writing a component
which communicates with a 3rd party DLL using WM_USER messages. After
loading the DLL, I need to tell the DLL the handle to send user
messages back to, so my unit can intercept them, but I don't know where
to get a handle from. I know how to do it in the mainform of a program
but not in a separate unit. The messages sent to the mainform do not
appear to reach my unit.</font></div>
<div> </div>
<div><font face="Arial" size="2">What do I need to do to make
this happen?</font></div>
<div> </div>
<div><font face="Arial" size="2"><font color="#000000">Thanks,</font></font></div>
<div><font face="Arial" size="2"><font color="#000000">Ross.</font></font></div>
<pre wrap=""><hr size="4" width="90%">
_______________________________________________
Delphi mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a>
<a class="moz-txt-link-freetext"
href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a>
</pre>
</blockquote>
<hr> _______________________________________________<br>
Delphi mailing list<br>
<a class="moz-txt-link-abbreviated"
href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a><br>
<a class="moz-txt-link-freetext"
href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a><br>
</blockquote>
<pre wrap=""><hr size="4" width="90%">
_______________________________________________
Delphi mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a>
<a class="moz-txt-link-freetext"
href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a>
</pre>
</blockquote>
<p> </p>
<hr> _______________________________________________<br>
Delphi mailing list<br>
<a class="moz-txt-link-abbreviated" href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a><br>
<a class="moz-txt-link-freetext" href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a><br>
</blockquote>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Delphi mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a>
<a class="moz-txt-link-freetext" href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a>
</pre>
</blockquote>
</body>
</html>