Pointers J/Direct Sample
This sample is located in \Samples\JDirect\Pointers.
Description
Using the Sample
Key Project Files
Technologies Demonstrated
Description
This sample prints out the version string of Kernel32.dll using the Microsoft® Win32® version APIs. The Pointers sample simulates pointers in Java as follows:
- A one-element int[] array simulates a pointer to a return buffer, in the pValBuffer argument to VerQueryValue.
- A byte[] array simulates a generic buffer in the pVerBuffer arguments to getFileVersionInfo and VerQueryValue.
- An int simulates the LPVOID pointer received from VerQueryValue.
- DllLib.ptrToStruct() parses the data addressed by an LPVOID pointer.
- DllLib.ptrToString() extracts a string addressed by an LPVOID pointer.
Note This is an example of how to deal with particularly difficult DLL functions. The specific task of getting version information for a file can be done much more easily using the FileVersionInformation class in com.ms.util.
Using the Sample
To run the sample
Run Go.bat in the \Samples\JDirect\Pointers directory.
Key Project Files
Pointers.java
The Pointers.getVersion method in this class does the following:
- Checks the module for version information.
- Creates enough space to hold the version information data block.
- Gets the version information.
- Gets the language entry array data for the target file.
- Uses the default (first) language entry in the array to generate the query string for the file version.
- Queries for the version string and returns it (if found).
The Pointers.intToHexString method generates an eight-character hexadecimal string that represents the integer value passed in. The string is padded with leading zeros as needed to make it eight characters long.
Technologies Demonstrated
Microsoft J/Direct
- This sample shows how to parse data through a double-indirected pointer.
© 1999 Microsoft Corporation. All rights reserved. Terms of use.