5 Steps to Safe Windows API Usage
1. Plan. Identify the tasks you want to accomplish. Define the results you expect. Think about how to implement the functionality you want to create: for example, as a function or a method.

2. Determine Resources. Sometimes you will need more than one API to accomplish your task. Many API calls are not named or grouped as you might think they would be. A good reference such as the Win32 Software Development Kit (SDK), MSDN, or other API reference work is required. Also, the Visual Basic API Declaration Viewer does not include all the possible messages so you might need to install Visual C++ in order to get at all the declarations and constants.

3. Test. Always code the Windows API portion of your program in a test program first. Once it's tested, then often you'll find a class wrapper for the API is an elegant solution. Wrapping a class around the API masks you from the declarations and provides a reusable component for next time.

4. Validate. When the API is coded into a class and tested, make sure it does what you want it to. Sometimes API calls can have unexpected side effects. For example, some APIs return strings with a null character (Chr$(0)) at the end. You will need to format return results to work they way you want them to, and how you decided they should work in step 1.

5. Handle Errors. You should always implement some form of error handling. Even API calls can fail. Test for and handle failure results in your implementation.