1

I am trying to access a global event created by native code in my java client. I am using JNA for this purpose to call OpenEvent method of kernel32.dll. But the method always returns NULL and GetLastError returns 2, which is File not found.

So I was wondering if JVM can see these global events and if so is there any other approach I can use?

-- Vinzy

vinzy
  • 13
  • 3
  • [this](http://stackoverflow.com/questions/3590226/working-example-of-jna-mouse-hook/4094882#4094882) might be helpful – jmj Jan 24 '11 at 19:13

1 Answers1

0

How do you call your openEvent?

I suppose it's something like this

int result = kernel32.OpenEvent( 10000, false, "Global\\nameOfEvent" ); //request for deletion

with the only difference you may be using objects as arguments, which, I suppose, is a matter of preference.

Maybe if you provide the code for the call we might be able to help you. Another thing to be asked is if you call CreateEvent in your native code somewhere. If you dig into the Windows API, you will notice that:

"The function succeeds only if some process has already created the event by using the CreateEvent function."

source : http://msdn.microsoft.com/en-us/library/ms684305(v=vs.85).aspx

Which in your situation mean you will be in a lot trouble if you were not the one creating the event. There is a way of obtaining a handle to an event you did not create but it's a bit more complicated and let's start by you providing a bit more information.

Cheers.

To sum it up:

If you don't call CreateEvent anywhere in your code you will have trouble when calling OpenEvent. To escape this problem you would basically have to find which process/thread holds the lock to the event and make it give it to your thread (the jvm's).

If you do call CreateEvent in your code then you should not have any problems obtaining a reference to your event and the culprit is somewhere else.

In any case, a bit more code would be nice.

Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72