I've recently fixed a bug in a VB6 application, but I'm not sure, what exactly went wrong.
The offending part was a wrong API declaration of CreateEvent
. This is, what API Viewer generated:
Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA"
(lpEventAttributes As SECURITY_ATTRIBUTES, ...) As Long
The next one is the wrong declare, obviously someone didn't want to import the SECURITY_ATTRIBUTES
structure...
Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA"
(lpEventAttributes As Any, ...) As Long
The call was:
Event = CreateEvent(Nothing, 0, 0, "MyEventName")
This call worked always in the IDE, but never from the compiled .exe. (CreateEvent
always returned 0)
I changed the declaration to:
Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA"
(ByVal lpEventAttributes As Any, ...) As Long
... and it worked.
Now I'm a little bit puzzled:
- Why is the parameter
ByRef
when usingSECURITY_ATTRIBUTES
but must beByVal
when usingAny
? - Why did the wrong declare always work in the IDE?