TcKs
TcKs

Reputation: 26632

Call of BroadcastSystemMessage never finish

I'm calling BroadcastSystemMessage method from User32.dll. On one PC (Windows8 Pro) the method is called, but the call never finishes. Application is waiting, but the result (nor exception) is never returned. I tried it on several Windows8 computers (different HW, with/without antivirus, etc...), but this behavior never happens on these computers.

Target computer doesn't have any installed or running application, which would register a custom message. So all applications should ignore the broadcast.

Is this behavior correct? I didn't see any mentions in MSDN about it. What's wrong? Is there some correct way to stop the call after some timeout?

Any advice or tip is welcome.

The code is:

[DllImport("user32", SetLastError = true)]
public static extern int BroadcastSystemMessage(MessageBroadcastFlags flags, ref MessageBroadcastRecipients lpInfo, uint Msg, IntPtr wParam, IntPtr lParam);
// ...... 
BroadcastSystemMessage(
    MessageBroadcastFlags.BSF_IGNORECURRENTTASK, // do not send message to this process
    ref MessageBroadcastRecipients.BSM_ALLDESKTOPS, // broadcast recipients
    msg, // registered private message
    IntPtr.Zero, // message-specific value
    IntPtr.Zero);
// ...... 
[Flags]
public enum MessageBroadcastFlags : uint {
    BSF_QUERY = 0x00000001,
    BSF_IGNORECURRENTTASK = 0x00000002,
    BSF_FLUSHDISK = 0x00000004,
    BSF_NOHANG = 0x00000008,
    BSF_POSTMESSAGE = 0x00000010,
    BSF_FORCEIFHUNG = 0x00000020,
    BSF_NOTIMEOUTIFNOTHUNG = 0x00000040,
    BSF_ALLOWSFW = 0x00000080,
    BSF_SENDNOTIFYMESSAGE = 0x00000100,
    BSF_RETURNHDESK = 0x00000200,
    BSF_LUID = 0x00000400
}

[Flags]
public enum MessageBroadcastRecipients : uint {
    BSM_ALLCOMPONENTS = 0x00000000,
    BSM_VXDS = 0x00000001,
    BSM_NETDRIVER = 0x00000002,
    BSM_INSTALLABLEDRIVERS = 0x00000004,
    BSM_APPLICATIONS = 0x00000008,
    BSM_ALLDESKTOPS = 0x00000010
}

Upvotes: 0

Views: 731

Answers (1)

I think this is a question for Raymond Chen - hopefully he'll see it.

Is there some correct way to stop the call after some timeout?

Sure, use the BSF_NOHANG flag.

Upvotes: 1

Related Questions