I'm experiencing some weird behaviour of boolean variables; the following code prints both "Hello" and "There", meaning result
& NOT result
both evaluate to True
Dim result As Boolean
result = PostMessage(Application.hWnd, 275, 0, 0)
Debug.Print "Post message: "; result
If result Then Debug.Print "Hello"
If Not result Then Debug.Print "There"
Outputs
Post message: True
Hello
There
According to the docs, PostMessage is declared like this:
BOOL PostMessageA(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
With the comment:
If the function succeeds, the return value is nonzero.
Here's how I have it in VBA:
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" ( _
ByVal hWnd As LongPtr, _
ByVal msg As Long, _
ByVal wParam As LongPtr, _
ByVal lParam As LongPtr) As Boolean
So what's causing the weird behaviour? How do I get around it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…