DWORDS ? LONG? - I need to create constants for the following

G

Guest

Hi Everyone,

I am creating an application to interface with Terminal Services but as you
will learn I am a beginner. I have learned how to connect to the API to use
the functions available. One of the functions I would like to use is the
following:

BOOL WTSWaitSystemEvent(
HANDLE hServer,
DWORD EventMask,
DWORD* pEventFlags
);

The following are my available choices for [DWORD EventMask]:

#define WTS_EVENT_NONE 0x00000000
#define WTS_EVENT_CREATE 0x00000001
#define WTS_EVENT_DELETE 0x00000002
#define WTS_EVENT_RENAME 0x00000004
#define WTS_EVENT_CONNECT 0x00000008
#define WTS_EVENT_DISCONNECT 0x00000010
#define WTS_EVENT_LOGON 0x00000020
#define WTS_EVENT_LOGOFF 0x00000040
#define WTS_EVENT_STATECHANGE 0x00000080
#define WTS_EVENT_LICENSE 0x00000100
#define WTS_EVENT_ALL 0x7fffffff <-- I am not sure how to convert
these and what they are?
#define WTS_EVENT_FLUSH 0x80000000

The constants will be Long in Visual Basic but how can I define what the
constant value will be? What will the long numerical value be? Hope I am
making sense..

Thanks
Jeremie Legault
(e-mail address removed)
 
G

Guest

Might have found my own answer, can someone confirm for me?

Is this right?
#define WTS_EVENT_NONE 0x00000000 = 0
#define WTS_EVENT_CREATE 0x00000001 = 1
#define WTS_EVENT_DELETE 0x00000002 = 2
#define WTS_EVENT_RENAME 0x00000004 = 4
#define WTS_EVENT_CONNECT 0x00000008 = 8
#define WTS_EVENT_DISCONNECT 0x00000010 = 16
#define WTS_EVENT_LOGON 0x00000020 = 32
#define WTS_EVENT_LOGOFF 0x00000040 = 64
#define WTS_EVENT_STATECHANGE 0x00000080 = 128
#define WTS_EVENT_LICENSE 0x00000100 = 256
#define WTS_EVENT_ALL 0x7fffffff = 2147483647
#define WTS_EVENT_FLUSH 0x80000000 = 2147483648

Thanks
Jeremie Legault
(e-mail address removed)
 
T

Tom Shelton

Jeremie said:
Hi Everyone,

I am creating an application to interface with Terminal Services but as you
will learn I am a beginner. I have learned how to connect to the API to use
the functions available. One of the functions I would like to use is the
following:

BOOL WTSWaitSystemEvent(
HANDLE hServer,
DWORD EventMask,
DWORD* pEventFlags
);

The following are my available choices for [DWORD EventMask]:

#define WTS_EVENT_NONE 0x00000000
#define WTS_EVENT_CREATE 0x00000001
#define WTS_EVENT_DELETE 0x00000002
#define WTS_EVENT_RENAME 0x00000004
#define WTS_EVENT_CONNECT 0x00000008
#define WTS_EVENT_DISCONNECT 0x00000010
#define WTS_EVENT_LOGON 0x00000020
#define WTS_EVENT_LOGOFF 0x00000040
#define WTS_EVENT_STATECHANGE 0x00000080
#define WTS_EVENT_LICENSE 0x00000100
#define WTS_EVENT_ALL 0x7fffffff <-- I am not sure how to convert
these and what they are?
#define WTS_EVENT_FLUSH 0x80000000

The constants will be Long in Visual Basic but how can I define what the
constant value will be? What will the long numerical value be? Hope I am
making sense..

If you are using VB.CLASSIC - then yes, they would be Long... But,
since this is a VB.NET group, I'll assume your using VB.NET - and in
that case, they will be integers. Integer in VB.NET is a 32-bit
number, not 16-bit as in VB.CLASSIC. A Long in VB.NET is actually a
64-bit number.

Anyway - to declare these:

Private Const WTS_EVENT_ALL As Integer = &H7FFFFFFF

In other words, change the 0x to an &H :) These look like a bunch of
flags that are going to be or'd together, so in reality I would
probably make these an Enum...

<Flags()> _
Private Enum EventFlags
None = &H0
Create = &H1
Delete = &H2
Rename = &H4
Connect = &H8
Disconnect = &H10
Logon = &H20
Logoff = &H40
StateChange = &H80
License = &H100
All = &H7FFFFFFF
Flush = &H80000000
End Enum

And then I would delcare the parameter that I was passing these to as
EventFlags. This way you get a handy intellisense on what flags are
valid :)

HTH
 
H

Herfried K. Wagner [MVP]

Jeremie Legault said:
Might have found my own answer, can someone confirm for me?
[...]
#define WTS_EVENT_FLUSH 0x80000000 = 2147483648

I don't see any reasons for transforming the hexadecimal literals into
decimal literals. Simply replace the '0x' with '&H' in VB.NET:

\\\
Private Const WTS_EVENT_FLUSH As Int32 = &H80000000
///
 
H

Herfried K. Wagner [MVP]

Jeremie Legault said:
I am creating an application to interface with Terminal Services but as
you
will learn I am a beginner. I have learned how to connect to the API to
use
the functions available. One of the functions I would like to use is the
following:

BOOL WTSWaitSystemEvent(
HANDLE hServer,
DWORD EventMask,
DWORD* pEventFlags
);

\\\
Private Declare Function WTSWaitSystemEvent Lib "Wtsapi32.dll" ( _
ByVal hServer As IntPtr, _
ByVal EventMask As WTS_EVENT_FLAGS, _
ByRef pEventFlags As Int32 _
) As Boolean

<Flags()> _
Private Enum WTS_EVENT_FLAGS
WTS_EVENT_NONE = &H0
WTS_EVENT_CREATE = &H1
WTS_EVENT_DELETE = &H2
WTS_EVENT_RENAME = &H4
WTS_EVENT_CONNECT = &H8
WTS_EVENT_DISCONNECT = &H10
WTS_EVENT_LOGON = &H20
WTS_EVENT_LOGOFF = &H40
WTS_EVENT_STATECHANGE = &H80
WTS_EVENT_LICENSE = &H100
WTS_EVENT_ALL = &H7FFFFFFF
WTS_EVENT_FLUSH = &H80000000
End Enum
///

The enumeration type is implicitly typed as 'Int32'.
 
Top