FuncPtr2 J/Direct Sample
This sample is located in \Samples\JDirect\Funcptr2.
Description
Using the Sample
Key Project Files
Technologies Demonstrated
Description
This example demonstrates a more advanced use of the com.ms.dll.Callback class. It displays all installed fonts.
To create a function pointer in Java
- Write a class that derives from com.ms.dll.Callback.
- Implement a public method named callback (all lowercase).
The callback method must be non-static, accept only integers as parameters, and return a value that has the integer, boolean, char, short, or void data type.
- Create an instance of your new class and pass it as the function pointer argument.
Using the Sample
To run the sample
Run Go.bat in the \Samples\JDirect\Funcptr2 directory.
Key Project Files
FuncPtr2.java
This class contains the following two classes:
- EnumFontsProc is an abstract class used to describe ENUMFONTPROCs (in general). In particular, it takes care of converting the callback arguments—all be declared as integers—into @dll.structs for easy parsing by the real callback function (enumFontsProc).
- SampleEnumFontsProc is a specific ENUMFONTPROC. It just prints the font face name.
Technologies Demonstrated
Microsoft J/Direct
This sample shows how to:
- Use the com.ms.dll.DllLib.ptrToStruct method to work around the limitation that the callback can take only integer parameters. The ptrToStruct method acts like a C-style cast.
- Use the auto parameter of @dll.struct.
© 1999 Microsoft Corporation. All rights reserved. Terms of use.