Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6884875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:33:51+00:00 2026-05-27T05:33:51+00:00

I’m using AllocateHWnd in a class I’m writing to receive system messages with a

  • 0

I’m using AllocateHWnd in a class I’m writing to receive system messages with a TWndMethod and the messages I’m receiving need to handle a 4-byte WPARAM, which specifically references a pointer. But I’m only getting 2 bytes in return. How do I set up things so I can correctly receive these messages within the class?

Edit: Specific code. I’m setting a message event up using SHChangeNotifyRegister, based on a Microsoft sample I downloaded. The proc works enough to pull back events (in lEvent) that I can buy off on, but the code Microsoft used defines WParam to be Thandle and LParam to be DWord. The specific problem I have is that when the function IsItemNotificationEvent is true, SHGetPathFromIDList is AVing or pulling back garbage. I kept looking this over and am not really seeing a problem other than what the docs I have indicate in that WParam is a Word (probably old) and that GetLastError at the point I put in the code returns “The handle is invalid”.

function IsItemNotificationevent(lEvent: Longint): boolean;
  var
    flagval: Longint;
  begin
    flagval := (lEvent and (SCHNE_UPDATEIMAGE or SHCNE_ASSOCCHANGED
            or SHCNE_EXTENDED_EVENT or SHCNE_FREESPACE
            or SHCNE_DRIVEADDGUI or SHCNE_SERVERDISCONNECT));
    Result := (flagval > 0);
  end;

procedure TShellNotifyHandler.WindowProc(Var msg: TMessage);
  var
    hNotifyLock: THandle;
    lEvent: Longint;
    pgpidl: PitemIDList;
    psi1: array[1..MAX_PATH] of Char;
  begin
    if Msg.Msg = FShellMsg then
      begin
        hNotifyLock := SHChangeNotification_Lock(THandle(Msg.WParam),DWord(Msg.LParam),
                 pgpidl, lEvent);
        writeln(SysErrorMessage(GetLastError));
        if (hNotifyLock > 0) then              
          begin
            if IsItemNotificationEvent(lEvent) then 
  // this limits events for this to what Microsoft defined in their example
               begin
                 if (pgpidl <> nil) then
                   SHGetPathFromIDList(pgpidl, @psi1);
                 Writeln('Path #1: ', String(psi1));
               end;
            SHChangeNotification_Unlock(hNotifyLock);
          end;
        if Assigned(FOnShellNotify) then
          FOnShellNotify(Self, LEvent);
      end
   else
      FWndProc(Msg);
  end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:33:52+00:00Added an answer on May 27, 2026 at 5:33 am

    Okay, I got this answered. A number of problems all over the board, actually:

    1) I had things wrong when it comes to IsItemNotificationEvent. To have valid PIDLs, I needed to make sure that the event WASN’T one of those, because no PIDL is valid to process against those.

    if IsItemNotificationEvent(lEvent) then 
    

    2) “out” was necessary in the definition to SHChangeNotification_Lock and not “var” or a simple pointer reference. I don’t have anything that indicates what “out” does specifically, so if anyone can help, please do. The fixed definition is below.

    function SHChangeNotification_Lock(hChangeNotification: THandle; dwProcessID: DWord;
         out pppidl: PSHNotifyStruct; out plEvent: Longint): THandle; stdcall;
    

    3) In my documentation (including the source samples), it indicates that multiple pidls are possible for some event types. Which makes the suggested correction invalid in the QC report. The problem with using the original definition is probably as suggested. It’s not quite right. Reference the definition above, and you’ll see a different type. That definition is below. No events have more than two parms, so it would suffice.

    TSHNotifyStruct = packed record
      dw1: PItemIDList;
      dw2: PItemIDList;
    end;
    PSHNotifyStruct = ^TSHNotifyStruct;
    

    Got it working as I expect it to now. I just need to find a valid list of two parm events and code in to make it a little cleaner (i.e. not reference the second pitemid if known to be invalid). Some samples of output from my test program are below to illustrate:

     Event received: $00001000 Parm 1: (C:) Local Disk  // update directory
     Event received: $00000008 Parm 1: ChangeNotifyWatcher // make directory
     Event received: $00000002 Parm 1: ChangeNotifyWatcher // create file
     Event received: $00000010 Parm 1: ChangeNotifyWatcher Parm 2: RECYCLER // remove directory
    

    Thanks all for your help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.