home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Sams Teach Yourself Visual J++ 6 in 21 Days
(Publisher: Macmillan Computer Publishing)
Author(s): Rick Leinecker
ISBN: 0672313510
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Summary

Visual J++ is a powerful language that makes it easy to develop applications. However, at times you’ll want to go directly to the Windows API. For this reason, you should always keep J/Direct as one of your alternatives when Visual J++ just doesn’t seem to give you what you need.

Using J/Direct is easy. While the examples in this chapter are simple, you can build on them and create your own powerful layers to the Windows API.

Q&A

Q How do you create a wrapper class and add methods that directly access the Windows API?

A You start by displaying the J/Direct Call Builder window. Then, you find the Windows API function that you want to add in the list box and double-click on it. Youill be asked if you want to add the class; then when you reply yes, the method on which you double-clicked will be added to a new class.

Q How do you pass a character string to a Windows API function that expects a pointer to a character buffer?

A J/Direct takes care of all data marshalling. For Windows API functions that take character buffers as arguments, you pass a Java String object. J/Direct will take care of the conversion details.

Q Why would anyone want to go to the trouble to access the Windows API directly? Isn’t Visual J++ enough?

A Every language from Visual C++ to Visual Basic to Visual J++ has occasion to need direct calls to the Windows API. There are so many things that programmers may require with regards to language functionality that languages can’t cover every single thing that may arise. For this reason, going directly to the Windows API can give you the method to solving your programming problems.

Q Where can I go for help when it comes to the Windows API?

A For starters, the Visual J++ online help is excellent. Try to find “Windows API” in the help index. Next to that, a good Windows API reference book would be helpful. Usually the books geared toward C and C++ programmers are best.

Exercises

1.  Create a Visual J++ application. Add a Windows API class named Win32 and add _lcreat(), _lwrite(), and _lclose() methods. Use _lcreat() to create a file, _lwrite() to write “Hello world!” to the file, and _lclose() to close the file.
2.  Create a new Visual J++ application. Add a Windows API class named Win32 and a GetSystemMetrics() method. Next, add constants such as SM_CXFULLSCREEN and SM_CYFULLSCREEN. Use these constants as arguments to the GetSystemMetrics() method and find out information about the system.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.