473,787 Members | 2,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about certain delare

I need to call CreateEvent, but I am getting a runtime error

An unhandled exception of type 'System.DllNotF oundException' occurred in
aa.exe
Additional information: Unable to load DLL (kernel32.lib).

Did I declare correctly?

Dim hevent As System.UInt32
hevent = CreateEvent(Int Ptr.Zero, True, False, "abc")

Declare Auto Function CreateEvent Lib "kernel32.l ib" ( _
ByRef lpEventAttribut es As IntPtr, _
ByVal bManualReset As Boolean, _
ByVal bInitialState As Boolean, _
ByVal lpName As String) As System.UInt32

Nov 21 '05 #1
9 1787
Hi,

To create an event you do just in a global part of your class (form)
Public (or whatever) event MyEvent

Than by instance in the form load
addhandler MyEvent, addressof MyEventSub

And in a method
raiseevent MyEvent

I hope this helps?

Cor

<that's fine>
I need to call CreateEvent, but I am getting a runtime error

An unhandled exception of type 'System.DllNotF oundException' occurred in
aa.exe
Additional information: Unable to load DLL (kernel32.lib).

Did I declare correctly?

Dim hevent As System.UInt32
hevent = CreateEvent(Int Ptr.Zero, True, False, "abc")

Declare Auto Function CreateEvent Lib "kernel32.l ib" ( _
ByRef lpEventAttribut es As IntPtr, _
ByVal bManualReset As Boolean, _
ByVal bInitialState As Boolean, _
ByVal lpName As String) As System.UInt32

Nov 21 '05 #2
Cor,
Thanks for your reply. Can you explain what I need to do to get
a handle of an event. I need the handle to use in

Declare Auto Function RegNotifyChange KeyValue Lib "Advapi32.l ib" ( _
ByVal hKey As System.UInt32, _
ByVal bWatchSubtree As Boolean, _
ByVal dwNotifyFilter As System.UInt32, _
ByVal hEvent As System.UInt32, _
ByVal fAsynchronous As Boolean) As System.UInt32

I hope this gives you a better idea of my problem.
Hopefully you or someone have some knowledge with declare's

Andy.

To create an event you do just in a global part of your class (form)
Public (or whatever) event MyEvent

Than by instance in the form load
addhandler MyEvent, addressof MyEventSub

And in a method
raiseevent MyEvent

I hope this helps?

Cor

<that's fine>
I need to call CreateEvent, but I am getting a runtime error

An unhandled exception of type 'System.DllNotF oundException' occurred in
aa.exe
Additional information: Unable to load DLL (kernel32.lib).

Did I declare correctly?

Dim hevent As System.UInt32
hevent = CreateEvent(Int Ptr.Zero, True, False, "abc")

Declare Auto Function CreateEvent Lib "kernel32.l ib" ( _
ByRef lpEventAttribut es As IntPtr, _
ByVal bManualReset As Boolean, _
ByVal bInitialState As Boolean, _
ByVal lpName As String) As System.UInt32



Nov 21 '05 #3
On 2004-11-27, <that's fine> <> wrote:
Cor,
Thanks for your reply. Can you explain what I need to do to get
a handle of an event. I need the handle to use in

Declare Auto Function RegNotifyChange KeyValue Lib "Advapi32.l ib" ( _
ByVal hKey As System.UInt32, _
ByVal bWatchSubtree As Boolean, _
ByVal dwNotifyFilter As System.UInt32, _
ByVal hEvent As System.UInt32, _
ByVal fAsynchronous As Boolean) As System.UInt32

I hope this gives you a better idea of my problem.
Hopefully you or someone have some knowledge with declare's

Andy.


Andy... First of all I would declare the above like this:

Declare Auto Function RegNotifyChange KeyValue Lib "Advapi32.d ll" ( _
ByVal hKey As IntPtr, _
ByVal bWatchSubtree As Boolean, _
ByVal dwNotifyFilter As Integer, _
ByVal hEvent As IntPtr, _
ByVal fAsyncronous As Boolean) As Integer

You don't need to use CreateEvent, since you could create a
ManualResetEven t (or AutoResetEvent) from System.Threadin g and pass in
it's Handle property - which is the native os handle, returned correctly
as an IntPtr.

You can declare the constants for hKey like this:

Public Shared ReadOnly HKEY_CLASSES_RO OT As IntPtr = New IntPtr
(TheValue)

Sorry, I'm not on windows to actually look up the value, but you get the
idea I'm sure :)

--
Tom Shelton [MVP]
Nov 21 '05 #4
"Tom Shelton" <to*@YOUKNOWTHE DRILLmtogden.co m> schrieb:
Public Shared ReadOnly HKEY_CLASSES_RO OT As IntPtr = New IntPtr
(TheValue)

Sorry, I'm not on windows to actually look up the value, but you get the
idea I'm sure :)


The value is '&H80000000'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
> > Declare Auto Function RegNotifyChange KeyValue Lib "Advapi32.l ib" ( _
ByVal hKey As System.UInt32, _
ByVal bWatchSubtree As Boolean, _
ByVal dwNotifyFilter As System.UInt32, _
ByVal hEvent As System.UInt32, _
ByVal fAsynchronous As Boolean) As System.UInt32
Andy... First of all I would declare the above like this:

Declare Auto Function RegNotifyChange KeyValue Lib "Advapi32.d ll" ( _
ByVal hKey As IntPtr, _
ByVal bWatchSubtree As Boolean, _
ByVal dwNotifyFilter As Integer, _
ByVal hEvent As IntPtr, _
ByVal fAsyncronous As Boolean) As Integer

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?

Also, assuming Integer and UInt32 are the same, why do you prefer to use
Integer?

Also, any ideas why my CreateEvent api is not found?

Also, do you know if LPCTSTR lpName can be declared as byref String

Finally, I already have hkey which I opend using
Dim reg As RegistryKey
reg = Registry.Classe sRoot
r = reg.OpenSubKey( s, False)
so why do I need the public shared below?
You don't need to use CreateEvent, since you could create a
ManualResetEven t (or AutoResetEvent) from System.Threadin g and pass in
it's Handle property - which is the native os handle, returned correctly
as an IntPtr.

You can declare the constants for hKey like this:

Public Shared ReadOnly HKEY_CLASSES_RO OT As IntPtr = New IntPtr
(TheValue)
I don't understand this?

Sorry, I'm not on windows to actually look up the value, but you get the
idea I'm sure :)

Nov 21 '05 #6
On 2004-11-27, <that's fine> <> wrote:
> Declare Auto Function RegNotifyChange KeyValue Lib "Advapi32.l ib" ( _
> ByVal hKey As System.UInt32, _
> ByVal bWatchSubtree As Boolean, _
> ByVal dwNotifyFilter As System.UInt32, _
> ByVal hEvent As System.UInt32, _
> ByVal fAsynchronous As Boolean) As System.UInt32
Andy... First of all I would declare the above like this:

Declare Auto Function RegNotifyChange KeyValue Lib "Advapi32.d ll" ( _
ByVal hKey As IntPtr, _
ByVal bWatchSubtree As Boolean, _
ByVal dwNotifyFilter As Integer, _
ByVal hEvent As IntPtr, _
ByVal fAsyncronous As Boolean) As Integer

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.Threadin g.ManualResetEv ent and System.Threadin g.AutoResetEven t.
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.Str ingBuilder. 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.Classe sRoot
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 RegNotifyChange KeyValue:

HKEY_CLASSES_RO OT
HKEY_CURRENT_CO NFIG
HKEY_CURRENT_US ER
HKEY_LOCAL_MACH INE
HKEY_USERS
You don't need to use CreateEvent, since you could create a
ManualResetEven t (or AutoResetEvent) from System.Threadin g and pass in
it's Handle property - which is the native os handle, returned correctly
as an IntPtr.

You can declare the constants for hKey like this:

Public Shared ReadOnly HKEY_CLASSES_RO OT As IntPtr = New IntPtr
(TheValue)


I don't understand this?


Which? The use of the Manual/AutoResetEvent or the declaring of the
constants..

' maybe in a class or form
Private myEvent As New ManualResetEven t (false)

' calling your function

RegNotifyChange dKeyValue (...., ...., ...., myEvent.Handle, ....)

It is a way of creating the possible constant values that can be passed
to RegNotifyChange KeyValue. 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 :)

--
Tom Shelton [MVP]
Nov 21 '05 #7
I almost understand, some more question to conclude (if possible?)
Also, do you know if LPCTSTR lpName can be declared as byref String

No. You would pass it ByVal.


O.k. so String works for C's strings.

Finally, I already have hkey which I opend using
Dim reg As RegistryKey
reg = Registry.Classe sRoot
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...


Do you mean that vb's OpenSubKey is not useful to obtain a handle ?

The declare is really a constant value that represents a predefined key
value. You can pass one of the following ot RegNotifyChange KeyValue:

HKEY_CLASSES_RO OT
HKEY_CURRENT_CO NFIG
HKEY_CURRENT_US ER
HKEY_LOCAL_MACH INE
HKEY_USERS
You can declare the constants for hKey like this:

Public Shared ReadOnly HKEY_CLASSES_RO OT As IntPtr = New IntPtr
(TheValue)


I don't understand this?


Which? The use of the Manual/AutoResetEvent or the declaring of the
constants..

' maybe in a class or form
Private myEvent As New ManualResetEven t (false)

' calling your function

RegNotifyChange dKeyValue (...., ...., ...., myEvent.Handle, ....)

It is a way of creating the possible constant values that can be passed
to RegNotifyChange KeyValue. 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 :)


Thanks for the sample code, it does explain how I should do it. At
the moment I am considering abandoning my project. I wanted to
write a reg-mon program like the one in www.sys internals.com , but now
I realise that just enumerating the keys is a 2 minutes ordeal or vb.
reg-mon seems not to have this problem, maybee they are not using
RegNotify... api.
Nov 21 '05 #8
On 2004-11-28, <that's fine> <> wrote:
I almost understand, some more question to conclude (if possible?)
> Also, do you know if LPCTSTR lpName can be declared as byref String
>


No. You would pass it ByVal.


O.k. so String works for C's strings.


LPCTSTR is pointer to a constant TSTR. TSTR is nice way of saying it
can be Unicode or Ansi depending on the system :)

> Finally, I already have hkey which I opend using
> Dim reg As RegistryKey
> reg = Registry.Classe sRoot
> 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...


Do you mean that vb's OpenSubKey is not useful to obtain a handle ?


Well it returns a RegistryKey object - and I don't see a way of geting
at it's native handle, which is what you would need to pass to the API
call.

The declare is really a constant value that represents a predefined key
value. You can pass one of the following ot RegNotifyChange KeyValue:

HKEY_CLASSES_RO OT
HKEY_CURRENT_CO NFIG
HKEY_CURRENT_US ER
HKEY_LOCAL_MACH INE
HKEY_USERS
>> You can declare the constants for hKey like this:
>>
>> Public Shared ReadOnly HKEY_CLASSES_RO OT As IntPtr = New IntPtr
>> (TheValue)
>
> I don't understand this?
>


Which? The use of the Manual/AutoResetEvent or the declaring of the
constants..

' maybe in a class or form
Private myEvent As New ManualResetEven t (false)

' calling your function

RegNotifyChange dKeyValue (...., ...., ...., myEvent.Handle, ....)

It is a way of creating the possible constant values that can be passed
to RegNotifyChange KeyValue. 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 :)


Thanks for the sample code, it does explain how I should do it. At
the moment I am considering abandoning my project. I wanted to
write a reg-mon program like the one in www.sys internals.com , but now
I realise that just enumerating the keys is a 2 minutes ordeal or vb.
reg-mon seems not to have this problem, maybee they are not using
RegNotify... api.


I wouldn't abandon it... It sounds like a good learning experience.

--
Tom Shelton [MVP]
Nov 21 '05 #9
> > I almost understand, some more question to conclude (if possible?)
> Also, do you know if LPCTSTR lpName can be declared as byref String
>

No. You would pass it ByVal.
O.k. so String works for C's strings.


LPCTSTR is pointer to a constant TSTR. TSTR is nice way of saying it
can be Unicode or Ansi depending on the system :)


Indeed yes, but vb strings are BSTR?


> Finally, I already have hkey which I opend using
> Dim reg As RegistryKey
> reg = Registry.Classe sRoot
> 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...


Do you mean that vb's OpenSubKey is not useful to obtain a handle ?


Well it returns a RegistryKey object - and I don't see a way of geting
at it's native handle, which is what you would need to pass to the API
call.


Reflection?

The declare is really a constant value that represents a predefined key
value. You can pass one of the following ot RegNotifyChange KeyValue:

HKEY_CLASSES_RO OT
HKEY_CURRENT_CO NFIG
HKEY_CURRENT_US ER
HKEY_LOCAL_MACH INE
HKEY_USERS

>> You can declare the constants for hKey like this:
>>
>> Public Shared ReadOnly HKEY_CLASSES_RO OT As IntPtr = New IntPtr
>> (TheValue)
>
> I don't understand this?
>

Which? The use of the Manual/AutoResetEvent or the declaring of the
constants..

' maybe in a class or form
Private myEvent As New ManualResetEven t (false)

' calling your function

RegNotifyChange dKeyValue (...., ...., ...., myEvent.Handle, ....)

It is a way of creating the possible constant values that can be passed
to RegNotifyChange KeyValue. 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 :)


Thanks for the sample code, it does explain how I should do it. At
the moment I am considering abandoning my project. I wanted to
write a reg-mon program like the one in www.sys internals.com , but now
I realise that just enumerating the keys is a 2 minutes ordeal or vb.
reg-mon seems not to have this problem, maybee they are not using
RegNotify... api.


I wouldn't abandon it... It sounds like a good learning experience.


Yes it is :-)
thanks for the assistance :-)

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2678
by: lothar.behrens | last post by:
Hi, I have problems to delare a delete operator in a class and use it to check for valid pointer. Using release() with an additional validation routine from a separate malloc library avoids the double deletion. The first delete will call the destructor and after it the delete operator
9
1942
by: jason | last post by:
how do you use the XmlValidatingReader to validate an XML document that is passed into the XmlValidatingReader constructor? it looks like the normal process is to use an underlying reader, as follows (C#): XmlValidatingReader oMyVReader = new XmlValidatingReader(oMyReader); oMyVReader.Schemas.Add(oMySchemaCollection); oMyVReader.ValidationType = ValidationType.Schema;
55
4676
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's not obvious how the code works if you don't know the intricacies of the Property Let/Get syntax. Likewise, I dislike (and code to minimize the use of) the VB/VBA syntax of returning a value by referring to the function name as if it were a...
5
1254
by: Greg Smith | last post by:
I am sure this is very simple but I can't seem to get the syntax correct. I have a class that I added to my application and I would like to reference controls on a webform. Something like: WebForm1.TextBox.Text = "Fred"; Any help is greatly appreciated.
6
2998
by: Woody Splawn | last post by:
I have a Winform where I fill a table with an associated dataset. This will put say 20 records into the table. I know this is elemental but... I want to see only one record from on my Winform from the dataset where the SSN = 547703330. SSN is the primary key for the table. At present I am using code like the following to determine if the specific record exists in the Dataset. Dim dtStudents As DataTable Dim drStudents As DataRow
1
880
by: John Verderber | last post by:
How would you delare a 2 dimensional array with 3 rows and 3 columns. I know this is really basic but I am just starting out. Derb
25
680
by: Jhon | last post by:
Hi every one, I got very basic question, here i go: Say i have 11001 11010 bits which are infact 10 bits. Now i want to address every bit so if it is zero i would add one and if it is one then i would be adding zero. Folks say it manchester coding. Please note that left hand side just accept a single bit for every operation.
25
2030
by: toton | last post by:
Hi, As inline is not mandetory, it depends on compiler to inline certain function (or using switch like fior GCC), my question is there any scope for inlining when it is not declared as inline function? i.e compiler may choose not to inline certain inline function, but is it free to choose a non inline function to inline it? I have some simple one line get function, and index operators which I want to get inlined. But due to some problem...
6
1632
by: lazy | last post by:
hi, I have some constants defined in a php script say config.php. I want to use the variables there defined in other scripts. couple of questions regd that: 1. Is there an alternative to including config.php and declaring the variables that will be used as global. This seems very inefficient. 2.Moreover these variables are constants, is there a way to make the variables unmodifiable in config.php so that scripts that use them ,
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10169
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.