Hi Tom, I have many questions
Why are you using an intptr for HKEY, HKEY as all win32 HANDLEs is
a DWORD, which is the same as int32?
Handle should be declared as IntPtr because IntPtr is the system pointer
size, and generally Handles are really pointers. In other words, a
HANDLE on a 64-bit system is not going to be 32-bit.
Also, assuming Integer and UInt32 are the same, why do you prefer to use
Integer?
UInt32 and Integer are not the same. They are the same size, but UInt32
is an unsigned 32-bit number and Integer is signed. To be honest it
doesn't really matter in this case... It's just that in general,
unsigned values are harder to work with in VB.NET since they are not
directly supported.
Also, any ideas why my CreateEvent api is not found?
Not sure... I didn't really look at that particular declare because it
isn't really needed. The framework already has an equivalent -
System.Threading.ManualResetEvent and System.Threading.AutoResetEvent.
If you need to pass them to an API call, they both provide a Handle
property.
Also, do you know if LPCTSTR lpName can be declared as byref String
No. You would pass it ByVal.
As a side note, if you're passing strings as buffers to be modified by
the API call you shouldn't pass them as strings at all. You should pass
them as System.Text.StringBuilder. VB.NET cheats, and actually lets you
use string - but there is overhead involved. In C#, you have to use
StringBuilder, so I think it pays to get into the habbit in case you
ever have to work in C#.
Finally, I already have hkey which I opend using
Dim reg As RegistryKey
reg = Registry.ClassesRoot
r = reg.OpenSubKey(s, False)
so why do I need the public shared below?
Well, you can't pass that regkey to your declare. It requires a handle.
So, if you plan on using this function, you'll need to open your
registry key with RegOpenKeyEx...
The declare is really a constant value that represents a predefined key
value. You can pass one of the following ot RegNotifyChangeKeyValue:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
Which? The use of the Manual/AutoResetEvent or the declaring of the
constants..
' maybe in a class or form
Private myEvent As New ManualResetEvent (false)
' calling your function
RegNotifyChangedKeyValue (...., ...., ...., myEvent.Handle, ....)
It is a way of creating the possible constant values that can be passed
to RegNotifyChangeKeyValue. You cant declare them as const, but the by
making them Shared ReadOnly in a class (or just public readonly in a
module) you get the same effect.
Admitedly, the Shared ReadOnly maybe sort of a c#'ism... I actually use
C# much more then VB.NET, so sometimes I tend to think that way