java可以访问使用CreateEvent创建的全局事件
我正在尝试访问由我的 java 客户端中的本机代码创建的全局事件。为此,我使用 JNA 来调用 kernel32.dll 的 OpenEvent 方法。但该方法始终返回 NULL,并且 GetLastError 返回 2,即找不到文件。
所以我想知道 JVM 是否可以看到这些全局事件,如果可以,我可以使用其他方法吗?
-- 文齐
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你如何调用你的 openEvent ?
我想这是类似的事情
,唯一的区别是你可能使用对象作为参数,我想,这是一个偏好问题。
如果您提供通话代码,我们也许能为您提供帮助。另一件要问的事情是,您是否在本机代码中的某处调用 CreateEvent。如果您深入研究 Windows API,您会注意到:
来源:http:// /msdn.microsoft.com/en-us/library/ms684305(v=vs.85).aspx
在您的情况下,这意味着如果您不是创建该事件的人,您将会遇到很多麻烦。是一种获取您未创建的事件的句柄的方法,但它有点复杂,让我们从您提供更多信息开始吧。
总结
一下:
如果您不在代码中的任何地方调用 CreateEvent。调用 OpenEvent 时会遇到问题。要避免这个问题,您基本上必须找到哪个进程/线程持有事件锁,并将其提供给您的线程(jvm 的),
如果您在代码中调用 CreateEvent,那么您就必须这样做 。获取对您的事件的引用应该不会有任何问题,并且罪魁祸首在其他地方。
无论如何,多一点代码会更好。
How do you call your openEvent?
I suppose it's something like this
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:
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.