3 messages in net.java.dev.jna.usersBuffer to Structure
FromSent OnAttachments
Thomas BörkelMar 19, 2008 5:06 am 
Timothy WallMar 19, 2008 5:33 am 
Thomas BörkelMar 19, 2008 8:42 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:Buffer to StructureActions...
From:Thomas Börkel (tho@boerkel.de)
Date:Mar 19, 2008 5:06:45 am
List:net.java.dev.jna.users

HI!

I am trying to call a function, that takes a buffer as parameter. This buffer could be anything, but is today a specific struct.

The function can be called with buffer length 0 to determine the needed buffer size. Then you call it again with the correct allocated buffer.

There are plenty of Win32 function that work like this.

But how do I later convert the buffer to the Structure? I only know a way to convert a Pointer to a Structure (with useMemory()).

This is the function: BOOL WINAPI QueryServiceStatusEx( __in SC_HANDLE hService, __in SC_STATUS_TYPE InfoLevel, __out_opt LPBYTE lpBuffer, __in DWORD cbBufSize, __out LPDWORD pcbBytesNeeded );

When I declare lpBuffer as type of the Structure and call the function first with cbBufSize = 0 and then with cbBufSize = pcbBytesNeeded, it works. But that's only for the current implementation.

For this, I have declared the function like this:

public boolean QueryServiceStatusEx(Pointer hService, int InfoLevel, SERVICE_STATUS_PROCESS lpBuffer, int cbBufSize, IntByReference pcbBytesNeeded);

But I'd like it more like this, to make it more future proof:

public boolean QueryServiceStatusEx(Pointer hService, int InfoLevel, byte[] lpBuffer, int cbBufSize, IntByReference pcbBytesNeeded);

But then how to convert lpBuffer to the Structure?

Thanks!

Thomas