I recently had a few drinks too many with my coworkers at the Russian Vodka Room and took the subway home. It’s a thirty minute ride during which I tried to implement EnumerateSecurityPackages in JNA. It was not a success and resulted in three dozen logs from JVM crashes. A good night sleep helped make it actually work.
This function wants a pointer to an array of pointer to a SecPkgInfo structure.
In JNA this one is simple. The Name and Comment fields need to be explicitly declared UNICODE and an inner ByReference child added so that SecPkgInfo can be returned.
So what’s a pointer to an array of these? It’s another structure that has the first item in the array as a reference within it. The first item can also auto-magically give us the entire array of a given size.
What’s a pointer to PSecPkgInfo now? It’s a PSecPkgInfo.ByReference. EnumerateSecurityPackages becomes:
Fortunately using this pointer to an array of pointers is a no-brainer.