🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: FindFirstChangeNotification - which File(s) was/were changed

#10712
From: Remy Lebeau (TeamB)
Date: Sat, 27 Mar 2004 06:52
61 lines
3689 bytes
"Dave" <dave_xse@-spam-hotmail.com> wrote in message
news:1cj24pzpnk6kq.7n0lajrj0cil$.dlg@40tude.net...

> I have done it but it just won't work yet...

It works fine when I use it in my own projects.

> The event is newer trapped by the Form's message
> handler somehow...

That is because you did not set it up correctly.

>     hNotify = SHChangeNotifyRegister(Form1->Handle,

You are calling your register code from within TForm1's constructor.  The
global Form1 pointer has not been assigned yet at that time.  You are lucky
your program did not crash from referencing an invalid pointer.  To use the
Handle from the constructor, you need to use the implicit 'this' pointer
instead, like you did when calling SHBrowseForFolder().

> WM_USER, cItems, Mine);

The last parameter of SHChangeNotifyRegister() expects a pointer, but you
are not passing a pointer at all.  You need to change your declaration to
use NOTIFYREGISTER* instead, and then pass your structure instance using the
'&' operator:

Also, the functions you are importing from Shell32 all use the __stdcall
calling convention, but your declarations are not specifying any calling
convention at all.  Unless your environment's default convention is
__stdcall (__cdecl is usually the default), then you will not be able to
call the functions correctly, and more importantly you will corrupt the
stack and thus your program will have undefined behavior from that point on.

Use this code instead (I suggest you use typedefs for make your code
clearer):

    typedef HANDLE (__stdcall *LPSHCNR)(HWND, DWORD, ULONG, UINT, DWORD,
NOTIFYREGISTER*);
    typedef BOOL (__stdcall *LPSHCND)(HWND);

    LPSHCNR lpSHChangeNotifyRegister;
    LPSHCND lpSHChangeNotifyDeRegister;

    lpSHChangeNotifyRegister = (LPSHCNR) GetProcAddress(hShell,
MAKEINTRESOURCE(2));
    lpSHChangeNotifyDeRegister = (LPSHCND) GetProcAddress(hShell,
MAKEINTRESOURCE(4));

Now, with that said, if you run your code under WinNT/2K/XP, then you need
to use SHChangeNotification_Lock() and SHChangeNotification_Unlock() as well
in order to get at the event information.  Under Win9x/Me, the event info is
contained inside the wParam and lParam values directly.  But under
WinNT/2K/XP, the OS creates a block of shared memory and then passes the
memory address to your code rather than the original data.  So you have to
lock the memory and then copy the desired data into your local storage, then
you can process the same values that Win9x/Me normally give directly.


Gambit
Technical Details
Message-ID: <40652272$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <gtsccansk388.1njug0ildrjsr$.dlg@40tude.net> <40648199@newsgroups.borland.com> <1cj24pzpnk6kq.7n0lajrj0cil$.dlg@40tude.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,255fcfa7b17a92b2
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-03-26 23:08:19 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <gtsccansk388.1njug0ildrjsr$.dlg@40tude.net> <40648199@newsgroups.borland.com> <1cj24pzpnk6kq.7n0lajrj0cil$.dlg@40tude.net>
Subject: Re: FindFirstChangeNotification - which File(s) was/were changed
Date: Fri, 26 Mar 2004 22:52:41 -0800
Lines: 63
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.138.253
Message-ID: <40652272$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1080369778 67.22.138.253 (26 Mar 2004 22:42:58 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail