28 messages in net.java.dev.jna.usersRe: [jna-users] Win32 Service Callbacks
FromSent OnAttachments
Thomas BörkelAug 21, 2007 6:26 am 
Thomas BörkelAug 22, 2007 12:35 am 
Wayne MeissnerAug 22, 2007 4:38 pm 
Thomas BörkelAug 22, 2007 10:36 pm 
Timothy WallAug 31, 2007 7:23 am 
Thomas BörkelAug 31, 2007 7:47 am 
Timothy WallAug 31, 2007 7:55 am 
Thomas BörkelSep 3, 2007 6:29 am 
Thomas BörkelSep 3, 2007 1:11 pm 
Timothy WallSep 6, 2007 11:21 am 
Thomas BörkelSep 7, 2007 7:08 am 
Timothy WallSep 7, 2007 7:43 am 
Thomas BörkelSep 10, 2007 12:18 am 
Thomas BörkelSep 10, 2007 4:36 am 
Timothy WallSep 10, 2007 5:43 am 
Thomas BörkelSep 10, 2007 6:49 am 
Timothy WallSep 11, 2007 4:47 am 
Thomas BörkelSep 11, 2007 6:15 am 
Timothy WallSep 11, 2007 6:47 am 
Thomas BörkelSep 11, 2007 6:52 am 
Timothy WallSep 11, 2007 8:52 am 
Thomas BörkelSep 11, 2007 10:26 pm 
Timothy WallSep 12, 2007 5:45 am 
Thomas BörkelSep 12, 2007 5:56 am 
Timothy WallSep 12, 2007 6:19 am 
Thomas BörkelSep 12, 2007 7:09 am 
Timothy WallSep 12, 2007 8:17 am 
Thomas BörkelSep 13, 2007 12:58 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Win32 Service CallbacksActions...
From:Thomas Börkel (tho@boerkel.de)
Date:Sep 12, 2007 5:56:47 am
List:net.java.dev.jna.users

HI!

Timothy Wall wrote:

not, then its strings may not be encoded the same as the library. Usually it's best (at least with windows) to define the structure within the library interface to ensure that the same mapping and encoding options are used.

Ah, I see. But it's strange, that it worked for another Structure with a String in the same source.

Perhaps the other structure was expecting "const char*" rather than "const wchar_t*"?

They were both LPTSTR and being passed to functions that are available as A and W versions.

OK, I see the problem. If you pass a Pointer, you are then responsible for ensuring Structure.write() gets called *before* the method call and that you call Structure.read() *after* the method call. When the Structure is an argument, the JNA library can automatically do that for you. When you pass the Pointer, the native memory behind the struct is probably still all zeroed, which would give you an empty description.

What you can do instead of declaring the param as Pointer, is declare an intermediate Structure from which all the other ones derive, e.g.

public static class OptionsStructure extends Structure { } public static class SERVICE_DESCRIPTION extends OptionsStructure { public String lpDescription; }

That will allow the structures to be interchangeable and still get the automatic structure read/write behavior.

Cool, I'll try that.

BTW, I've been tinkering with launching java.exe directly as a service, but the process always seems to exit immediately. I'm not sure how to figure out why, though. I can install/uninstall directly from Java without problems, but when I try to start the service it appears that the process quits immediately (I get two event log errors - "process failed to respond" and "process timed out after 30s").

I have now a complete working example of an abstract Win32 service class in Java. Also, I have defined lots of needed Win32 functions and constants for services and for registry access. I can contribute that. What do I have to do?

Thomas