Missing Topic or Incorrect Help ID

This page intentionally left blank.

If you have reached this topic, please report the incorrect or missing jump as an error in the SmartCheck help system.


Getting Started

Welcome to SmartCheck

For a brief introduction to SmartCheck, see:

  SmartCheck Overview

  Default SmartCheck Behavior

Running SmartCheck

To start a SmartCheck session, see either of these topics:

To check a program from Visual Basic

To check a program directly from the SmartCheck

   Related Topics


 SmartCheck Overview

SmartCheck is a run-time debugging tool that addresses the most problematic conditions encountered by Visual Basic developers:

•	Fatal run-time errors that are cryptic and hard-to-solve

•	Problems that result from a sequence of events

•	Incorrect Windows API Usage from Visual Basic

•	Bad values passed to built-in Visual Basic functions

•	Problematic value coercions

•	Errors in components, such as ActiveX controls, used by your program

How SmartCheck works

As you run an executable program, SmartCheck runs in the background monitoring it continuously, and logging program events and errors.

The information captured by SmartCheck can be viewed in a Program Results window, either during or after running a program. You can also save a session’s log file for later review.

SmartCheck automatically searches for errors in your program executable as well as the dynamic-link libraries (DLLs), third-party modules, and OLE components used by your program. It can also find errors in programs for which you do not have source code, though we recommend that you have source code with debugging information to maximize error detection and diagnosis.

SmartCheck checks all API calls, memory allocations and deallocations, Windows messages, and other significant program events for errors such as:

•	Common memory errors, including memory overruns and memory leaks

•	Resource leaks, including Windows-specific handles

•	Windows-specific errors in Win32APIs, ODBC, DirectX, and COM/OLE APIs

For a list of the errors SmartCheck detects, click here.

   Related Topics


Errors Detected by SmartCheck

SmartCheck detects the following categories of errors in your program.

 Interface Method Failures

 Leaks

 Memory Errors

 Procedure and Function Failures

 Visual Basic Runtime Errors

If a program includes C/C++ components that have been instrumented with BoundsChecker, version 5.0, FinalCheck, checking will also detect:

 Pointer Errors


Interface Method Failures Detected by SmartCheck

•	Invalid Interface Method Argument – Conflicting combination of flags

•	Invalid Interface Method Argument – Out of range

•	Invalid Interface Method Argument – Structure size field not initialized

•	Invalid Interface Method Argument – Undefined or illegal flags

   Related Topics


Leaks Detected by SmartCheck

SmartCheck tracks memory and resource allocations specifically as they pertain to the Windows API and to components written in languages such as C or C++. This specific type of tracking does not apply to programs or components written in Visual Basic.

•	Interface leak

•	Memory leak

•	Resource leak

If a program includes C/C++ components that have been instrumented with BoundsChecker, version 5.0, FinalCheck, these errors will also be detected:

•	Memory leaked due to free

•	Memory leaked due to re-assignment

•	Memory leaked leaving scope

   Related Topics


Memory Errors Detected by SmartCheck

•	Dynamic Memory Overrun

•	Freed handle is still locked

•	Handle is already unlocked

•	Memory allocation conflict

•	Pointer references unlocked memory block

•	Stack memory overrun

•	Static memory overrun

If a program includes C/C++ components that have been instrumented with BoundsChecker, version 5.0, FinalCheck, these errors will also be detected:

•	Reading overflows memory

•	Reading uninitialized memory

•	Writing overflows memory

   Related Topics


Pointer errors detected by SmartCheck
Pointer Errors

If a program includes C/C++ components that have been instrumented with BoundsChecker, version 5.0, FinalCheck, checking will also detect:

•	Array index out of range

•	Assigning pointer out of range

•	Expression uses dangling pointer

•	Expression uses unrelated pointers

•	Function pointer is not a function

•	Returning pointer to local variable

•	Unallocated pointer

   Related Topics


Procedure and Function Failures Detected by SmartCheck

•	API failure: Windows function failed

•	API failure: Windows function not implemented

•	Invalid argument

•	At least one format specifier is illegal

•	Bad combination of values

•	Bad destination pointer

•	Bad handle

•	Bad path

•	Bad source pointer

•	Class not specified

•	Conflicting combination of flags

•	Empty variable not allowed

•	Error object not allowed

•	File number not opened

•	File number out of range

•	Format string is not followed by valid arguments

•	Invalid pointer to format string

•	Item not found

•	Network path not allowed

•	Not enough arguments for this format String

•	Null variant not allowed

•	Out of range

•	Structure size field is not initialized

•	Too many arguments for this format String

•	Undefined or illegal Flags

•	Wild cards not allowed

•	Questionable use of thread

   Related Topics


Visual Basic Runtime Errors Detected by SmartCheck

•	Component Creation failure

•	Conversion failure

•	File acess failure

•	Cannot find specified file system object

•	File already open

•	No disk in drive

•	No permission to access file

•	Inappropriate wildcard match

•	File read/write failure

•	File system object already exists

•	Invalid array operation

•	Invalid form operation

•	Invalid function declaration

•	Invalid operation

•	Invalid pattern string

•	Invalid property value

•	Registry entry not found

•	Type mismatch

   Related Topics


Default SmartCheck Behavior

By default, SmartCheck:

•	Uses an error detection scheme that checks for the most common errors and events in Visual Basic programs.

•	Provides detailed analysis of unhandled Visual Basic runtime errors.

•	Immediately reports each error it encounters, providing detailed error information and providing options through which you can determine how to handle subsequent instances of the given error in the current session.

•	Opens a Program Results window, after the program finishes, and reports the events and errors generated by your program as it executed. The Program Transcript window, which reports the order in which program components load, appears in minimized form toward the bottom of the display.

SmartCheck provides settings with which you can vary the error and event detection schemes, and other aspects of the SmartCheck environment. If you are working in the Visual Basic environment, select SmartCheck Settings from the Run menu; in the SmartCheck application, select Settings from the Project menu.

Note that under the default configuration, SmartCheck:

•	Does not check for errors in components for which no source code is available. However, there may be times when you need to pinpoint errors generated by third-party components for which you have no source code. In this case, before running your program under SmartCheck, select the Report errors even if no source code is available setting (To access this setting, click Advanced on the Error Detection tab of the Settings dialog).

•	Expects source code to reside in the same directory as the program executable. If necessary, you can identify additional directories in which SmartCheck should search for source code. (For example, you may need to add to your search path in order to have SmartCheck locate the source code for DLLs used by your program. You can also specify a working directory if you do not want to debug your program in the same directory as your program executable.) Use Source File Search Path under the Program Info tab of the Settings dialog to identify additional directories.

•	Reports, but does not analyze, errors for which you have written your own error handlers. To have SmartCheck include your handled errors in its analysis, select the Perform analysis of handled Visual Basic runtime errors setting before running your program. (To access this setting, click Advanced on the Error Detection tab of the Settings dialog).

•	Does not report API and OLE calls. To have SmartCheck log events for these calls, disable the Suppress system API and OLE calls setting. (To access this setting, click Advanced on the Error Detection tab of the Settings dialog).

(For additional help on SmartCheck settings, bring up the Settings dialog and use context-sensitive help to view definitions of each option.)

When you finish running and checking your program, you can use the SmartCheck Program Results window to review and filter your program’s error and event data, and to view the source code in which the error occurred. You can also choose to save, print, or send the event data logged by SmartCheck.

   Related Topics


Copyright Notice

Information in this help system is subject to change without notice and does not represent a commitment on the part of NuMega Technologies, Inc. The software described in this help system is furnished under the software license agreement distributed with the product. The software may be used or copied only in accordance with the terms of the license. No part of this help system may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic or mechanical, including photocopying or recording for any purpose other than the purchaser’s personal use, without prior written permission from NuMega Technologies, Inc.

Copyright © 1997 NuMega Technologies, Inc.
All Rights Reserved

The following identifies the trademarks of products or companies referenced in this online Help system.

NuMega Technologies, the NuMega logo, SmartCheck, the SmartCheck icon, ActiveCheck, FinalCheck, SmartDebugging are trademarks of NuMega Technologies, Inc.

Microsoft, Windows, Win32, Win32s, Windows NT, Windows 95, Visual C++, Visual Basic and Visual Studio are either trademarks or registered trademarks of the Microsoft Corporation.

Borland and Delphi are either trademarks or registered trademarks of Borland International, Inc.

Other brand and product names are either trademarks or registered trademarks of their respective holders, and are used herein for reference purposes only.


Review SmartCheck Basics
 Reading the SmartCheck Basics Manual

Before you start using SmartCheck, we recommend that you take the time to read the SmartCheck Basics manual. This manual provides an overview of SmartCheck and explains how to use its most popular features.

SmartCheck Basics is available in both hard-copy and online versions.

To review SmartCheck Basics online

1	On the Start menu, click Programs, then point to NuMega SmartCheck.

2	Click SmartCheck Basics to access the online manual.

Online Help

The SmartCheck Online Help explains in detail how to perform specific tasks in your development environment.  Click Related Topics to learn how to access the various forms of available Online Help.

   Related Topics


How to Use Online Help
 Using Online Help

In addition to the online Help that you can access from the SmartCheck Help menu, help is available on each dialog option or field, from the Program Error Detected window, and from any SmartCheck window or dialog. By default, SmartCheck also provides status bar Help.

To control status bar Help

   On the View menu, click Status Bar. By default, the Status Bar is enabled.

To display troubleshooting information on detected errors

In the Program Error Detected window, click Explain.
– or –
In the Program Results window, click the right-mouse button, then click Explain. SmartCheck displays a description of the detected error.

To display a description of a dialog control, option, or entry field

   Click [image] in the dialog title bar, then click on the control or option. You can also display context-sensitive Help by tabbing to a control, then pressing F1.

To display instructions for tasks

   Click [image] in a SmartCheck dialog.

To display a description of a SmartCheck window

   Press F1.

 Related Topics


 Checking Multiple ActiveX Executables (EXEs)

SmartCheck automatically detects errors in your program executable and any in-process servers (i.e., any DLLs) started by your program. SmartCheck cannot automatically check out-of-process servers (i.e., any EXEs) started by your program, since each SmartCheck session “sees” a single process only. For example, if your program launches instances of Microsoft Word and Excel, SmartCheck detects errors in your program, but does not check for errors in either Word or Excel.

To detect errors in out-of-process servers started by your program, you must start multiple, concurrent SmartCheck sessions, one for each EXE to be checked, and one for your program, using these steps:

1	Start a stand-alone SmartCheck session.

2	Open the out-of-process, executable file to be checked.

3	On the Program menu, select Settings, and click the Program Info tab.

4	At Command-line options, type:

-embedding

5	Repeat steps 1 - 4 for each out-of-process server to be checked. For example, to check both Word and Excel, you would complete steps 1 - 4 twice, once to open Winword.exe, and once to open Excel.exe.

6	Open your program in SmartCheck, and start running and testing it as you normally would. You can open your program either through SmartCheck options in the Visual Basic environment, or by starting another instance of stand-alone SmartCheck.


 Error Detection Settings

Use settings on the Error Detection tab to:

  Select error detection categories.

  Indicate whether SmartCheck should report detected errors immediately when they occur in your program.

  Save current settings for all new programs.

Tips

•	To have SmartCheck use the current settings as the new defaults for new programs, select Save these settings as the initial values for new programs.

If you never use this option to save a custom configuration, SmartCheck uses its original, default error detection scheme, on every new program.

•	Choosing additional error detection categories affects performance. You should consider this factor when customizing error detection for your program.

•	When you make any changes to the default SmartCheck settings, SmartCheck enables the Default Settings command on the Error Detection tab. You can click Default Settings at any time to re-instate the default SmartCheck configuration for the program.

•	To view a definition of any item in the Settings dialog, click [image] then click on the item you want to learn more about.

   Related Topics


Set the error detection scheme
To Select Error Detection Categories

1	Under Types of Errors to Check For, click the checkbox to the left of any error category, or category sub-setting, to select or clear it.

2	Click (highlight) the name of an error category to review any sub-settings associated with it. The sub-settings appear under Additional Settings. Click the checkboxes to the left of these sub-settings to select or clear them.

3	Click Advanced to review advanced error detection settings. Click OK to save any changes you make.

4	In the main Settings dialog, click OK again, to save any changes made to the main settings.

5	When you have set and saved error detection options, run SmartCheck on your program.

Tips

Under its default configuration, SmartCheck:

•	Does not check for errors in components for which no source code is available. The assumption is that you will primarily be checking your own programs. However, there may be times when you need to pinpoint errors generated by third-party components for which you do not have source code. In this case, before running your program under SmartCheck, select the Report errors even if no source code is available setting (under Advanced settings, accessible from the error detection settings tab.)

•	Reports, but does not analyze, errors for which you have written error handlers. To have SmartCheck include your handled errors in its analysis, select the Perform analysis of handled Visual Basic runtime errors setting before running your program.


Report detected errors immediately
To Report Errors Immediately

1	Select Report Errors Immediately to have SmartCheck report each error immediately when it occurs during program execution.

When this setting is enabled, SmartCheck provides detailed information about each error in the Program Error Detected window. Using options in this window, you can choose to acknowledge the error, suppress further reports of that error, or display a detailed description of error causes and potential solutions.

When this option is disabled, SmartCheck still records detected errors and events in an event log for your program. The same level of detailed error information that appear in the Program Error Detected window will be available to you through options in the Program Results window, after you finish running your program.

2	Click OK to save your changes.


Save current error detection settings
To Save Error Detection and Reporting Settings

To have SmartCheck use the current settings as the defaults for all new programs:

1	Select Save these settings as the initial values for new programs.

2	Click OK to save your changes.

Tips

•	If you are displaying the original, default SmartCheck configuration, and have not yet made any changes to it, this option will not appear.

•	If you never use this option to save a custom configuration, SmartCheck uses its original, default error detection scheme for every new program.

•	To restore the default error detection configuration for the current program, click Default Settings.


 Advanced Error Detection Settings

Use Advanced settings to select additional error detection options.

1	Click checkboxes to select or clear any Advanced options.

2	Click OK to save your changes.

Tips

Note that under the default configuration, SmartCheck:

•	Does not check for errors in components for which no source code is available. However, there may be times when you need to pinpoint errors generated by third-party components for which you have no source code. In this case, before running your program under SmartCheck, select the Report errors even if no source code is available setting

•	Reports, but does not analyze, errors for which you have written your own error handlers. To have SmartCheck include your handled errors in its analysis, select the Perform analysis of handled Visual Basic runtime errors setting before running your program.

•	Suppresses reporting of API and OLE calls to maximize SmartCheck performance. However, there may be times when you find it useful to track these calls in order to diagnose difficult problems. To have SmartCheck log events for these calls, disable the Suppress system API and OLE calls setting.


Collecting and Reporting Program Events
 Reporting Settings

Use settings on the Reporting tab to identify which program events SmartCheck should collect and report, and to indicate whether or not SmartCheck should analyze and report handled runtime errors.

1	Click checkboxes to select or clear any Reporting options.

2	Click OK to save your changes.

Tips

•	Note that data collection and analysis activities do affect run-time performance and the size of the program event log. Many users find that the default SmartCheck configuration offers the optimum level of data collection and error and event analysis.

•	To view a definition of any specific item in the list, click [image] then click on the item you want to learn more about.

•	The Perform analysis of handled Visual Basic runtime errors setting on the Reporting tab is a sub-option of Report handled Visual Basic runtime errors, and therefore only available when that setting is selected.

•	You can choose to collect event data before you run your program, then filter the display of these events when you view Program Results.

   Related Topics


Specifying Source Files, Directories, and Run Options
 Program Information Settings

Use settings on the Program Info tab to:

  Specify a working directory

  Specify program command-line options

  Set the source file search path

Tip

•	SmartCheck uses the search path to find and display the source code associated with the events and errors it detects in your program. You may need to add to your search path in order to have SmartCheck locate the source code for DLLs used by your program. You can also specify a working directory if you do not want to debug your program in the same directory as your program executable.

   Related Topics


Specify a working directory
To Specify a Working Directory

1	Enter the working directory for your program. If you do not specify a working directory, SmartCheck will run in the directory where your program executable (.EXE) resides. You can click the Browse button associated with this entry to search your system.

Note SmartCheck always creates the event log for your program in the same directory as your program executable, regardless of your specified working directory.

2	Click OK to save your changes.


Specify program command-line options
To Specify Program Command-line Options

1	Type any command-line arguments to control how your program is run.

2	Click OK to save your changes.


Set the source file search path
To Specify the Source File Search Path

1	At Source File Search Path, type the directory path(s) SmartCheck should use to locate your source files. Separate paths with semicolons.

You can click the Browse button associated with this entry to search your system and select directories to add to the path. The path for each directory you select is appended to the current sequence of search paths.

2	Click OK to save your changes.

Tip

•	If you are prompted for and provide the location of source files when running a program or examining program results, SmartCheck adds the appropriate path to the program's search path.


Working with Error Suppression Libraries
 Error Suppression Settings

Use the options on the Error Suppression tab to selectively suppress SmartCheck error checking in parts of your project.

For more information, see:

   Select a suppression library

   Add an API function to a suppression library

   Remove a suppression item from a library

Tips

•	SmartCheck creates a separate suppression library for each program you open. This library is located in the same directory as your program executable, and has the extension .SUP. SmartCheck also provides suppression libraries for common development environments, OCXs and DLLs, including Visual Basic, MFC, Visual C++, Delphi VCL, and OWL.

•	You cannot add or remove suppression items from the suppression libraries supplied with SmartCheck.

•	Each time you suppress an error from the Program Error Detected or Program Results window and choose to save suppression information, SmartCheck adds this information to your  program's suppression library. To learn more about how to suppress an error while checking a program, click here [image].

   Related Topics


Enable or disable a library
To Select or Clear a Suppression Library

1	In the Available Suppression Libraries list box, click a suppression library.

2	Review the suppression items contained in the selected library. Click on the list box headings to view suppression items in alphabetical order according to Type, Location, or Scope.

3	Select or clear that library.

4	Click OK to save your changes.


Remove a suppression item
To Remove a Suppression Item From a Library

1	In the Available Suppression Libraries list box, click a suppression library.

2	Review the suppression items contained in the selected library. Click on the list box headings to view suppression items in alphabetical order according to Type, Location, or Scope.

Note that you cannot add or remove suppression items from the suppression libraries supplied with SmartCheck.

3	Select the suppression item(s) you want to remove from the library.

4	Click Remove Item.

5	Click OK to save your changes.


Add or suppress an API function
Adding an API function to a suppression library

You may want to suppress an API function when you know that your program makes API calls but does not check call-returns.

Note that you cannot add or remove suppression items from the suppression libraries supplied with SmartCheck.

To add an API function

1	Click on the library you want to modify.

2	Click Add API Function.

3	Select a DLL from the drop-down list.

4	Click the name of the function you want to add to the suppression library.

5	Click OK to save your changes.


 Suppressing Detected Errors

The Suppress dialog is available through either the Suppress command in the Program Error Detected window or the Suppress menu option in the Event pane of the Program Results window.

The Suppress options let you suppress subsequent instances of the currently identified error. You can limit the scope of  suppression to specific source files or modules. You can also choose to save suppression information for future runs of the program. This information is recorded in a suppression library for your program.

Note that you cannot suppress an error from a previously saved program results (.SCE) file.

To select an error suppression option

1	Click an option to suppress further instances of this error.

To view a description of each suppression option, click [image] and click the option.

2	Click OK.

If you suppressed the error from the Program Error Detected window, SmartCheck will not log subsequent instances of the error to the program event log.

If you suppressed the error from the Results window, SmartCheck will suppress (gray-out) that error in the Results window. The next time you run your program in the current debugging session, SmartCheck will not log subsequent instances of the error to the program event log.

To save suppression settings for future use

1	Click Save Suppression Information.

2	Click OK. The setting is stored in the program's error suppression library.

Tips

•	You cannot suppress fatal Visual Basic runtime errors

•	It is possible to suppress errors that occur when using built-in Visual Basic functions, however doing so may prevent analysis of subsequent errors.

   Related Topics


 Suppressing Errors - Options

You can choose to suppress subsequent instances of a specific error from the Program  Error Detected and Program Results window.

There are two main reasons you might want to suppress an error:

•	The error was generated by code belonging to another member of the development team or by a third party DLL or OCX.

•	Your code properly handles the error. For example, SmartCheck detects an API failure, but your code handles this failure.

When you suppress an error, you can limit the scope of suppression to specific source files or modules. You can also choose to save suppression information for future runs of the program.

Note that you cannot suppress an error from a previously saved program results (.SCE) file. You must be running your program to suppress errors from the Program Results window.

For more information, see:

   Suppress an error from the Program Error Detected window

   Suppress an error from Program Results

   Share suppression libraries with a team

   Related Topics


Suppress an error as you check your program
 Suppressing an Error From the Program Error Detected window

You can suppress subsequent instances of the selected error in the same function, executable, DLL, or source file. Subsequent instances of the error will not be entered in your program’s event log. You can also choose to save these suppression settings for use when checking your program in the future.

Note  Use the Report Errors Immediately setting to enable or disable use of the Program Error Detected window.

To set error suppression from the Program Error Detected window

1	Click Suppress.

2	Select a suppression option, and enter any necessary information.
To view a description of each suppression option, click [image] and click on the option.

3	If you want to save this suppression setting for when you check the program again, select Save Suppression Information. The setting is stored in the program's error suppression library.

4	If you want, add a comment for future reference.

5	Click OK to save your settings.

To save suppression settings for future use

1	Click Save Suppression Information. The setting is stored in the program's error suppression library and will take effect the next time you run your program.

2	Click OK.

   Related Topics


Suppress an error from the Results window
Suppressing an Error From the Program Results Window

You can choose to suppress subsequent instances of the selected error in the same function, executable, DLL, or source file. You can also choose to save these suppression settings for use when checking your program in the future.

Note that you cannot suppress an error from a previously saved program results (.SCE) file. You must be running your program to suppress errors from the Program Results window.

To set error suppression from the Program Results window

1	Check your program.

2	Display the Program Results window for your program.

3	Select the error you want to suppress, then click the right-mouse button.

4	Select Suppress….

5	Select a suppression option, and enter any necessary information. To view a description of each suppression option, click [image] and click the option.

6	If you want to save this suppression setting, select Save Suppression Information. The setting is stored in the program's error suppression library. When you run your program again, SmartCheck will not report the suppressed error.

7	If you want, add a comment for future reference.

8	Click OK to save your settings. SmartCheck grays out instances of the selected error according to your settings.

To save suppression settings for future use

1	Click Save Suppression Information. The setting is stored in the program's error suppression library. When you run your program again, SmartCheck will not report the suppressed error.

2	Click OK.

Tips

•	You cannot suppress fatal Visual Basic runtime errors

•	It is possible to suppress errors that occur when using built-in Visual Basic functions, however doing so may prevent analysis of subsequent errors.

   Related Topics


 Sharing Suppression Libraries With a Team

SmartCheck gives you the ability to customize an error suppression library and distribute it for your entire development team to use. You might want to share a suppression library because:

•	The project uses a third-party library or DLL that produces errors when run under SmartCheck. Once you are aware of these errors, subsequent detection by SmartCheck is not necessary.

•	The application your team is developing produces errors under SmartCheck, but the team has determined that these errors are benign.

In either case, we recommend that the task of creating a shared suppression library be undertaken by senior members of the team who have the technical expertise to discern which errors to suppress.

To create and share a suppression library

1	Run your program with SmartCheck and suppress the errors you want to include in the suppression library.

SmartCheck saves the suppression information in a file located in the program's directory and named PROGRAM-NAME.SUP. For example, if your program is named TEST.EXE, the suppression library name is TEST.SUP.

2	Edit the .SUP file with an ASCII editor and change the first line from

//SUPPRESSIONPROJ:program-name
to
//SUPPRESSIONLIB:description-of-the-library.

3	When:

•	Using runtime libraries (DLLs or OCXs)

For each DLL or OCX you want to include in the suppression library, add the line:

//USESMODULE: dll_or_ocx_name

For example,

//USESMODULE: COMCTL32.OCX

•	Using statically linked-in libraries

If the suppression entries in the file are specific to a C/C++ control and you would like SmartCheck to automatically detect whether you should use this set of suppressions when testing new applications that may incorporate this control, add this line in the form:

//SYMBOL:”symbol-name”

Symbol-name must be a symbol that uniquely identifies the control and is linked into any application that uses the control. If the symbol has C++ linkage, you must use the mangled (or decorated) version of that symbol name. For example, all Windows applications that use MFC contain a reference to the symbol CWinApp::Run. The Microsoft C++ compiler transforms this into the decorated name ?Run@CWinApp@@UAEHXZ. Therefore, a suppression file that refers to MFC would contain the line:

//SYMBOL:"?Run@CWinApp@@UAEHXZ"

You may have to examine the map file for your application to discover an appropriate symbol name to use in this way.

4	Once you have changed the //SUPPRESSIONLIB line and optionally added a	//SYMBOL line, save the file.

5	Have each member of the team copy the suppression file to the SmartCheck \DATA directory. This is the default location for suppression files.

   Related Topics


Checking Specific Source Files and Modules
 Files to Check

SmartCheck lets you narrow the error detection focus by selecting the specific program  modules and source files you want to check. You may want to check for errors only in code you have recently written yourself and not in other project modules. Or, you may want to check for errors in a new DLL or OCX you have coded, but not in existing modules.

Note that SmartCheck does not automatically display the DLLs and OCXs dynamically linked by your program. You can exclude these modules from error checking by first adding the modules, then clearing the modules or related source files you do not want to check.

For more information, see:

   Check specific modules (EXEs, DLLs, and OCXs)

   Check specific source files

   Add or remove a program module

   Related Topics


Check specific modules (EXEs, DLLs, and OCXs)
Checking Specific Modules (EXEs, DLLs, and OCXs)

SmartCheck automatically checks all DLLs and OCXs used by your program, unless you specify otherwise.

You can narrow the checking focus by:

•	Specifying which DLLs and OCXs you want SmartCheck to include when checking your program.

•	Excluding the program’s .EXE file from the checking run.

Note that SmartCheck does not automatically display the DLLs and OCXs dynamically linked by your program. You can exclude these modules from error checking by first adding the modules, then clearing the modules or related source files you do not want to check.

To check specific modules (EXEs, DLLs, and OCXs)

1	In the Modules list box, select the program module you want to check for errors.

2	Click OK to save your changes.

To exclude specific modules (EXEs, DLLs, and OCXs)

1	In the Modules list box, clear the program module you do not want to check for errors.

2	Click OK to save your changes.


Check specific source files
Checking Specific Source Files

SmartCheck automatically checks all source modules in your program. You can narrow the checking focus by selecting specific source files that you want SmartCheck to check. This can simplify the error detection process and let you focus on your own code first.

Note that SmartCheck displays source files only if you built the specified program with debug information.

To check specific source files

1	In the Modules list box, select the program module for which you want to view source files.
If the program module is not listed, add that module before proceeding to the next step.

2	In the Source Files list box, select the source files you want to check for errors.

3	Click OK to save your changes.

To exclude source files from error checking

1	In the Modules list box, select the program module for which you want to view source files.
If the program module is not listed, add that module before proceeding to the next step.

2	In the Source Files list box, clear the source files you do not want to check for errors.

3	Click OK to save your changes.


Add or remove a program module
Adding or Removing a Program Module

SmartCheck automatically checks all of your program’s DLLs and OCXs, but only displays in the Modules list the modules loaded by your program at run time. To display modules dynamically loaded by your program,  you must first  add one of these modules, then choose the associated source files that you do or do not want to check.

To add a program module (EXE, DLL, or OCX)

1	Click Add Module. The Add Module dialog appears.

2	Select or type the program modules you want to check for errors, then click Open. You can select multiple modules by pressing the Shift key as you choose modules.

3	Click OK to add the selected module(s).

To remove a program module (EXE, DLL, or OCX)

1	Select the program modules you want to remove. You can select multiple modules by pressing the Shift key as you choose modules.

2	Click Remove Module.

3	Click OK to remove the selected module(s).


Program Error Detected Window

The Program Error Detected window displays detailed information about the cause of an error and its location in your source code.

For additional help on any item or area of the Program Error Detected window, click the help icon, ?, in the upper right corner of the window, then click on the item or area about which you want information.

Tips

•	Before running your program, use the Report Errors Immediately setting (on the Error Detection tab under Settings), to enable or disable use of the Program Error Detected window.

•	The detailed error information that appears in the Program Error Detected window is also available to  you when reviewing program results.


 Reviewing a Program Transcript

As your program loads and executes, SmartCheck displays program debug and other events in the Program Transcript window. These events are signaled by the operating system as you debug your program.

By default, the Program Transcript window appears in minimized form in the lower left corner of the SmartCheck display.

The Program Transcript window displays the following debugging events:

Create process	Exit process
Create thread	Exit thread
Load DLL	Unload DLL
Exception	Output debug string
To save debug events to a text file

1	Select the event text that you want to save.

2	On the SmartCheck Edit menu, click Copy. The selected text is copied to the Windows clipboard.

3	Open the Windows clipboard, then save the event text as a file.

   Related Topics


 Reviewing Program Results

The Program Results window displays the errors and events detected when checking your program.  Note that the error detection options you selected before running your program determine which errors and events SmartCheck detects and records.

To learn more about your program results, see:

   Identifying each view in the Program Results window

   Identifying program error and event types

   Analyzing program details and call stacks

   Showing the source code associated with an error

   Displaying error descriptions and repair suggestions

   Finding program errors and events

Tips

•	You can use your program results to trace, identify, and analyze program errors and their location in your source code. You can locate general problems by tracing the sequence of events. You can also examine events that affect your program’s performance, such as unnecessary data value coercions, or unexpected program actions. For example, referencing the property of a control might cause an unexpected form load.

•	You can resolve API failures by reviewing program API calls and arguments. (To review API and OLE calls, be sure to disable the Suppress API and OLE Calls setting before running your program.)

•	Use options on the View menu to display an event summary for your program results, or filter the display of errors and events in the Program Results window. Use options on the File menu to save or print program results. Click Related Topics for information on how to perform these tasks.

•	When you choose to display program events, the Program Results window presents a hierarchical, expandable events listing. In this view, error messages may be nested within events, and therefore, not immediately visible. You can click the + icons to the left of events to expand the view, and reveal the error messages. Alternatively, a useful approach to reviewing errors is to:

1	Click [image] (Show Errors and Leaks Only) in the SmartCheck toolbar to first view errors only.

2	Click on an error message that you want to examine.

3	Click [image] (Show Errors and Specific Events) to view the sequence of events that led to the error.

   Related Topics


Program Results Window

The following describes each view in the Program Results Window.

   Related Topics


Identify Program Error and Event Types
Identifying Program Error and Event Types

Depending on the errors and events SmartCheck detected in your program, your program data may include the following event types.

Note  The Program Results window can display only the errors and events you checked for when running SmartCheck on your program. If you do not see an error or event you expected, check your  SmartCheck Settings and rerun your program if necessary.

Icon	Event Type	Description
	Errors	SmartCheck adds an error event to the event log when it detects an error in your program. The error message describes the error type and other available information, such as related argument types and values.
	Resource, Memory and OLE Leaks	SmartCheck detected a memory, resource, or interface method leak. The message describes the leak.
	Thread Starts	SmartCheck detected the creation of a thread.
	Thread Context Switch	SmartCheck detected that your program has switched from one thread to another.
	API  Calls  OLE  Method Calls	SmartCheck adds a Call-return event to the event log when your program makes an API or OLE call and then returns from the call.  Note that a running Visual Basic program makes many calls to the Windows API behind-the-scenes. By default, SmarCheck does not report these behind-the-scenes calls, since knowing about them is generally not useful. However, it does, by default, report all explicit API calls you make within your Visual Basic code and add them to the event log, tagged with the icon for  “Visual Basic Intrinsic and Local API calls” shown below. Call-returns that contain nested events are designated with a plus sign. To see the nested events, click the plus sign to expand the event. When you expand a Call-return event, SmartCheck uses Expanded Call and Expanded Return icons to designate the individual calls and returns.
	Visual Basic Instrinsic and Local API calls	SmartCheck logs this event each time your Visual Basic program uses an intrinsic (built-in) Visual Basic function such as Msgbox, Mid$ and CurDir. Local API calls are calls you make from Visual Basic to external libraries such as WIN32API.
	Object Property Get, Object Property Let Object Method Call	These events represent setting and referencing properties and calling methods of your Visual Basic controls. Examples include: setting Command1.Caption = “Hello”; testing the value of Command1.Caption; invoking Command1.SetFocus. When a property “let” occura, SmartCheck shows the new value being assigned; when a property “get” occurs, SmartCheck shows the line of code in which the property was retrieved (though not the value being retrieved). While actions involving controls are reported, note that method calls on external objects (such as “Excel.Worksheet”) will not be seen. SmartCheck supports all built-in Visual Basic controls, and all the controls that come with the Visual Basic 5.0 Enterprise edition. SmartCheck can also “see into” third-party OCXs that use IDispatch::Invoke to communicate with Visual Basic. (SmartCheck does not log events fired by controls that use the “dual interface” mechanism.)
	Visual Basic Form and Control Creations	These events represent the creation of Visual Basic forms and controls. Note that after either of these events occurs, the control exists although no user-written code has been executed for the code yet. Typically, when a new form loads, you will see a form creation even, followed by events that represent the creation of controls on the form. It is important to realize that the reporting of a form creation event is distinct from the reporting of a call to a user-written Form-load procedure.
	Visual Basic Value Coercions	SmartCheck logs this event each time Visual Basic performs a value coercion, that is, converts a variant’s value from one data type to another. For example, if you pass the string “123” to a function that expects a numeric value, Visual Basic converts the string to a numeric data type. SmartCheck logs both the input and output value and type. SmartCheck coercion reporting is particularly valuable for less obvious coercions automatically performed by Visual Basic. For example, if you pass a variable of type “Single”, with a value of 123.456, to a function tha texpects an integer parameter, Visual Basic “silently” truncates the value to 123.
	Visual Basic Error Handlers and Resumes	SmartCheck tracks runtime errors you handle in your Visual Basic code. It shows you when the error occurs, the first error handler statement that executes and the statement at which your program resumes after an error. Error handlers and resumes are filtered out by default.
	Window and Dialog	SmartCheck adds a Message event to the event log when the program processes a dialog or Windows message.
	Hook	SmartCheck adds a hook event to the event log when the program processes a Windows hook call. The function name and arguments are included on the line.
	Comments	SmartCheck adds a comment event to the event log when your program makes a call to OutputDebugString.

   Related Topics


Analyze Program Details and Call Stacks
Analyzing Program Details and Call Stacks

You can review additional information for program events in the Details pane of the Program Results window. You can use this information to trace the events that led to a program error and examine detailed argument data for Visual Basic built-in functions, API and OLE calls and returns.

The details pane shows the window handle of forms and controls as they are created. It also shows values and data types for data value coercions and new values assigned to control properties.

You can also choose several views of call stack data for memory allocation errors for C, C++ and Delphi components.

SmartCheck does not display details when additional event information does not exist or is not available (such as for program comments, hooks, and output debug strings).

To review the call stack(s) for a leak or error

1	Select the leak or error in the Program Results window.

2	If there are multiple call stacks for the error, click on the drop-down list in the Details pane and choose to view the call stack from the:

Location  of error	Shows the order of function calls starting with the function where SmartCheck detected the selected error.
Point of allocation	Shows the order of function calls starting with the function that allocated the memory block referenced by the selected error.
Point of deallocation	Shows the order of function calls starting with the function that deallocated the memory block referenced by the selected error.
3.	Click on a function to view the associated source code, if available.

To view detailed data for API or OLE function calls

1	Select the API or OLE function call in the Program Results window.

2	Review the arguments, values, and addresses for that function call in the Details pane.

Note Visual Basic sometimes passes arguments as pointers. (A pointer  holds the address in memory at which a value is stored, rather than holding the value itself.)  When arguments are passed as pointers, SmartCheck shows both the pointer and the value referenced by the pointer.

Tips

•	If you select the Arguments option on the View menu, the Program Events and Detail panes include detailed information about the arguments passed to Visual Basic built-in functions. You will see:

•	The values of all arguments explicitly passed by your program to a function

•	Either default values or placemarkers for any optional arguments for which your program did not supply values. Specifically, if Visual Basic supplies a default value for an unassigned, optional argument, SmartCheck displays that value. If Visual Basic does not supply a default value for an optional argument, SmartCheck displays VARIANT: Missing for that argument in the Program Events pane. In the Details pane, VARIANT:Missing arguments display as Long .scode values.

For example, the Msgbox function requires you to specify a prompt, but its other parameters (buttons, title, helpfile, and context) are optional. There are no default values for the title, helpfile or context arguments, therefore, SmartCheck will record them as VARIANT: Missing arguments if they are not specified by your program.

•	If a Visual Basic built-in function takes a comma-delimited, list of arguments, unlimited in number, SmartCheck only logs the required arguments. For example, the write function accepts an unlimited number of arguments, i.e.;

write #1, var1, var2, var3, "abc", var4...

Only the first argument (the file number --> #1) is required, and therefore, it is the only one logged.

•	When displaying arguments of type "Date", the Event pane shows the date value, for example, "1-1-97". The Details pane shows the value of the underlying data type for "Date", which is a double.


Display source code for an error
Displaying Source Code for an Error

You can use the Program Results window to display the source code that caused or led to a program error. SmartCheck displays source code, if available, in the source pane of the Program Results window.

If SmartCheck cannot find the source code for an error but could locate the line number from the .EXE, SmartCheck prompts you to set the source file location.

Note that you cannot edit source code displayed in the Program Results window.

To display source code for an error in SmartCheck

   In the Program Results window, click an error or a function in the call stack for that error. The associated source code, if available, appears in the bottom pane of the Results window. If necessary, SmartCheck prompts you for the location of source files.

To restart a source code search in SmartCheck

   On the Edit menu, click Go To Source.
-- or –
Select an event, press the right-mouse button, then click Go To Source.

When you select Go To Source, SmartCheck disregards any information it has previously collected about the location of source files and begins a new search. If necessary, SmartCheck prompts you for the location of source files.


Find Errors and Events in the Results Window
 To Find Errors and Events in the Program Results Window

1	Select or open the Program Results window for your program.

2	On the Edit menu, click Find.

3	If shown, click [image], then select Error or an event type.
-- or –
In the Find What box, type the text of the error or event you want to find.

4	Click Find Next or, if shown,  Find Previous.

To find other occurrences of a specified event

   On the Edit menu, click Find Next or Find Previous.  SmartCheck searches for additional instances of the previously specified item.

To find other occurrences of an error

   On the Edit menu, click Find Next Error or Find Previous Error.


Display an error description for a selected error
To Display an Error Description for a Selected Error

1	Select an error in the Program Results window.

2	Click the right-mouse button, then choose Explain.
A detailed description of the detected error appears, along with sample code and suggested repair information. You can click on the buttons at the top of the error description to jump to a specific section.


 Changing Your View of Errors and Events

You can choose which program events (in addition to errors) you want to view in the Program Results window. This makes it easy to check a program's flow and to isolate specific program functions as separate groups of events. By default, SmartCheck shows Visual Basic events, program errors and leaks.

You can only view the errors and events you chose to collect and report before running SmartCheck on your program.

Note that your selections in this dialog affect only your view of error and event information; your selections do not change the contents of the program’s event log.

For more information, see:

   To change the display of program events

   To save settings for all new programs

Tip

•	You can change your view of errors and events using commands on either the SmartCheck View menu or the toolbar.

   Related Topics


Change the display of program events
To Change the Display of Program Events

1	Use options on the View menu to filter the display of information in the Program Results window.  The options include: Show Errors and Leaks only, Show All Events, or Show Errors and Specific Events (the default).

If you choose Errors and Specific Events, the Program Results window displays all errors, along with all currently selected Specific Events.

2	On the View menu, click Specific Events to select the types of events to display. The default SmartCheck selection includes a subset of events commonly found useful by Visual Basic developers.

For a description of event types, click here [image].

3	Click Apply to see how your selections change the information displayed in the Results window.

4	Click Close when you are satisfied with your selections.

Tip

When you choose to display program events, the Program Results window presents a hierarchical, expandable events listing. In this view, error messages may be nested within events, and therefore, not immediately visible. You can click the + icons to the left of events to expand the view, and reveal the error messages. Alternatively, a useful approach to reviewing errors is to:

1	Click [image] (Show Errors and Leaks Only) in the SmartCheck toolbar to first view errors only.

2	Click on an error message that you want to examine.

3	Click [image] (Show Errors and Specific Events) to view the sequence of events that led to the error.


Save event settings
To Save Event Settings

1	Select Apply to all new windows to display the specified events in all new instances of the Program Results window.

SmartCheck uses these settings to display program results when you next run the current program or any other program.

2	Click OK.


 Finding Data in a SmartCheck Window

Use the Find option to search for an error or event in the Program Results window or to find a text string in a Program Transcript or Compliance Report.

In addition to using the menu commands described below, you can use items on the SmartCheck Standard toolbar to perform searches. For a description of toolbar options, click here [image].

To find an error or event in the Program Results window

1	Select the Program Results window for your program.

2	Click [image], then select Error or an event type.

3	Click Find Next or Find Previous.

To find other occurrences of an error or event in the Program Results window

1	Select the Program Results window for your program.

2	On the Edit menu, click:
Find Next Error or Find Previous Error if your last search was for a program error.
Find Next or Find Previous if your last search was for a selected event.

To find text in the Program Transcript, Program Results window, or Compliance Report

1	Display or select the Program Transcript, Program Results, or Compliance (program or event) window for your program.

2	Select the top line in the window.

3	In the Find What box, type the text string for which you want to search.

4	Click Find Next or Find Previous.

   Related Topics


 Reviewing a Compliance Report

SmartCheck ComplianceView technology checks your program's compliance with Microsoft's three 32-bit APIs (Win32s, Win32 for Windows 95, and Win32 for Windows NT) and creates a comprehensive report based on the results. This compliance report includes:

•	A list of API functions used, categorized by the API

•	C Run-Time Library calls that are not supported by ANSI C

•	Undocumented functions

API Function Categories

SmartCheck categorizes the API functions as follows:

•	Functions included only in Win32 for Windows NT

•	Visual Basic built-in functions

•	Functions included in Win32 for Windows NT and Win32 for Windows 95

•	Functions included only in Win32 for Windows 95

•	Functions included in Win32s, which implies inclusion in Win32 for Windows NT and Win32 for Windows 95

•	ANSI C functions

•	ANSI C extensions

•	Visual Basic built-in functions

•	Undocumented functions (titled "Other" on the Compliance report)

Undocumented Calls

ComplianceView also checks the program for any undocumented calls. You can use functions that are not currently described in the Win32 API documentation, but it is important that you know which functions are supported and which are not.

ANSI C Functions

ComplianceView shows your program's use of the C Run-Time Library calls that are not supported by ANSI C.

   Related Topics


 Saving a Compliance Report

You can save the contents of your Program Compliance or Event Compliance report if you want to review your program’s compliance information at a later time.

If you exit SmartCheck without saving your compliance report, SmartCheck will prompt you to do so. By default, SmartCheck assigns the compliance report the same name as your program, with a .SCX extension.

To save a compliance report

1	Display the Program or Event Compliance window for your program.

2	On the File menu, click Save As.

3	Enter a file name and select a directory location. You can accept the default .SCX extension for your program or supply your own.

4	Click Save.

   Related Topics


Sending a Compliance Report

You can send a copy of your current or a saved compliance report to another person on your team. To view a program results file, the recipient of the file must have the same version of SmartCheck.

To send a compliance report

1	On the File menu, click Send. SmartCheck displays your current MAPI-supported mail program and begins a new message with an included program or event compliance report file. By default, SmartCheck names the compliance report your-program-name.SCX.

2	Type or select the name of the person(s) you want to receive a copy of the included program results.

3	Type any other information you want to add.

4	Send the mail message using the appropriate method for your mail program.

   Related Topics


 Setting SmartCheck Window Preferences

You can customize the appearance of SmartCheck windows by selecting the font used to display program data. For example, you may want to increase the size of the error data you view most frequently, or decrease font sizes to display more information in a window.

To change the fonts used in SmartCheck windows

1	Click a SmartCheck display item. For a description of each item, click here [image].

2	Click Change Font to change the text size or style of the selected Item. You can view a sample of your current selections in the Sample box.

3	Choose OK to save your changes.

To restore preference settings to SmartCheck defaults

   Click Restore Defaults.

   Related Topics


SmartCheck Preference Items

Call stack	Controls the display of stack information in the Program Error Detected window and the Results window.
Compliance  report	Controls the display of text in the SmartCheck Compliance window.
Program results	Controls the display of the error and event list in the Results window.
Program transcript	Controls the display of program status information in the Program Transcript window.
Source code	Controls the display of source code in the Program Error Detected window and the Results window.
   Related Topics


 Selecting Toolbars and Tooltips

You can choose from several SmartCheck toolbars, which provide shortcuts for frequently used commands. By default, SmartCheck displays all of its toolbars. You can also choose whether to display tooltips, which identify toolbar controls when you move the mouse pointer over that control.

To control the display of toolbars

1	Select or clear the toolbars you want to display.  SmartCheck displays or hides the related toolbar as you make your changes.
For a description of each SmartCheck tool bar, click here

2	Click Close to save your changes and exit the dialog.

To control the display of tooltips

1	Select or clear Show Tooltips.

2	Click Close to save your changes and exit the dialog.

To restore toolbar settings

   Click Reset. The toolbar and tooltip options revert to the last-saved settings.

   Related Topics


SmartCheck Toolbars

You can use the SmartCheck toolbars as follows:

Toolbar	Function
Event view	Change the display of events to:  Show errors and leaks only Show all events Show errors and specific events
Standard	Manage programs and files: Open programs Copy text from a window Print program results Find, Find Next, Find Previous Context sensitive help
Program Execution	Set error detection options  and run programs: Run SmartCheck on your program Halt a SmartCheck run Report detected errors immediately


 Installing Support for Additional Compilers

By default, SmartCheck installs error-checking support for components created using Microsoft Visual C.

You can have SmartCheck, instead, install error-checking support for any one, or all, of the compilers listed below. Manually copy the correct DEFAULT.XXX file, located in the SmartCheck \DATA directory, to DEFAULT.DAT.

Compiler	DEFAULT file name
Microsoft C/C++	DEFAULT.MSC
Borland C/C++	DEFAULT.BOR
Symantec C/C++	DEFAULT.MSC
Watcom C/C++	DEFAULT.BOR
Borland Delphi 2.x	DEFAULT.DPH
All compilers	DEFAULT.ALL
   Related Topics


 Getting Troubleshooting Information

If you need additional information on SmartCheck, we suggest you try the following sources for current troubleshooting information.

•	Review the SmartCheck ReadMe file.

On the Start menu, click Programs, point to NuMega SmartCheck, and then choose the appropriate SmartCheck ReadMe file for the SmartCheck edition you purchased.

•	Visit the NuMega Web site.

On the Help menu, click NuMega on the Web. Your Web browser will open and search for NuMega’s Web site (www.numega.com).  Select the link for SmartCheck Frequently Asked Questions to review available product information.

If you have reviewed the above and still experience problems, contact NuMega Customer Support as defined in the Contact NuMega Help topic.

   Related Topics


Contacting Customer Support

For Non-Technical Issues

NuMega Customer Service is available to answer any questions you might have regarding upgrades and other order fulfillment needs. Customer Service is available from 8:30am to 5:30pm EST, Monday through Friday. Call:

•	In the U.S. and Canada: 888-283-9896

•	International: +1 603 578 8103

For Technical Issues

NuMega Technical Support can assist you with all your technical problems, from installation to troubleshooting.

Before contacting technical support please read the relevant sections of the documentation and the Readme files.

To contact Technical Support, by:

•	Telephone: Telephone support is available as a Priority Support Service from 8:30am to 5:30pm EST, Monday through Friday. Have product version and serial number ready.

In the U.S. and Canada, call: 888 NUMEGA-S.

International customers, call: +1 603 578 8100

•	E-Mail: Include your serial number and send as many details as possible to:

Tech@numega.com

•	World Wide Web: Submit issues and access additional support services at:

www.numega.com.

Go to Support.

•	Fax: Include your serial number and send as many details as possible to:

603 578 8401

Before calling, please obtain and record the following information:

•	Product name (or edition), version, or service pack.

•	Product serial number.

•	Your system configuration: operating system, network configuration, amount of RAM, environment variables, and paths.

•	The details of the problem; settings, error messages, stack dumps, and the contents of any diagnostic windows.

•	If the problem is repeatable, the details of how to create the problem.

•	The name and version of your compiler and linker and the options you used in compiling and linking.


Value of argument x (x_value) must be larger than y (y_value)
Invalid argument: bad combination of values

Value of argument x (x_value) must be larger than y (y_value)

 Description    [image] Sample Code    [image] Repair

Description

An argument that should have held the larger of two values passed to a function, held the smaller value instead. For example, in the Visual Basic IPmt function, the third parameter, which represents a total number of payments, must be greater than the second parameter, which represents the number of the current payment.

Sample Code

In this example, assume CurInstall and TotInstall are set to user-supplied values. If CurInstall is greater than TotInstal, the following code results in an error.

...
CurInterest = IPmt(APR / 12, CurInstall, TotInstall, -LoanPrincipal)
...

Repair

Review how your program sets the pair of arguments identified in the error description, and ensure that their respective values are always appropriate for the given function.


If the first argument is less than zero, the second must be an integer
Invalid argument: bad combination of values

If the first argument is less than zero, the second must be an integer

 Description    [image] Sample Code    [image] Repair

Description

Two arguments specified by your program resulted in an invalid use of exponents. Specifically, in the expression x ^ y (x raised to y), whenever x is less than 0, y must be an integer. The arguments passed by your program did not conform to this rule.

Sample Code

In this example, assume Base and Exponent are set to user-supplied values. If the user enters a negative number, for example, “-5”, for Base, and a non-integer value, for example, 1.5, for Exponent, the following code results in an error.

...

Answer = Base ^ Exponent

...

Repair

Review how your program sets the values in question, and be sure your logic always results in values that are valid for the intended operation.


Invalid Argument: Bad path

 Description    [image] Sample Code	   Repair

Description

Your program passed an invalid path specification as an argument to a function or statement.  This error may have resulted from passing:

•	An empty string, or a string that contains only spaces,  in a context where this is not allowed

•	A path specification that contains errors in syntax

Sample Code

In this example, assume NewDir is set to a user-supplied value. If no code is included to check for valid user entries, this value may either be null or contain invalid syntax, in which case an error will result.

NewDir = txtDirName.Text
   .
   .
   .
MkDir NewDir

Repair

Review how your program sets the path information. Ensure that your logic always results in a valid path.


Invalid argument: Class not specified

 Description    [image] Sample Code	   Repair

Description

Your program passed an empty string, or an uninitialized variable, as the class name argument to either the CreateObject or GetObject function.

Sample Code

Dim xlApp As Object ' Declare variable to hold the reference.

Dim ClassType

ClassType = "excel.application"

' The spelling error in the following line results

' in an uninitialized variable getting passed to CreateObject.

Set xlApp = CreateObject(ClassTyp)

...

Repair

•	Review how your program sets the given argument, and ensure that it always contains a valid value.

•	Using the Option Explicit statement in your program modules will prevent errors resulting from mistyped variable names.

A related topic in the Visual Basic Help system:

•	Option Explicit statement

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Invalid argument: Error object not allowed

 Description    [image] Sample Code	 Repair

Description

Visual Basic provides an intrinsic Err object that captures information about runtime errors. Your program attempted to pass this object as an argument in a context where this is not allowed.

Sample Code

Dim temp
Dim FirstPart
Dim SecondPart
On Error GoTo ErrHandler
temp = Text1.Text
FirstPart = Left(temp, InStr(temp, " ") - 1)
' The next line will now fail
' because temp was used in the error handler
SecondPart = Right(temp, InStr(temp, " ") + 1)
' ....
Exit Sub

ErrHandler:
    temp = CVErr(5)
    Call LogError(temp)
    Resume Next

Repair

•	If you intended to use the Err object, you may want to review these related topics in the Visual Basic help system:

•	Err Object

•	CVErr function

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)

•	If you did not intend to use the Err object, you may have mistakenly set some variant in your program to this object, and then passed it as an argument to a function that expected a different data type. If this is the case, review how you are setting values for the given variant.


Invalid argument: File number not opened

 Description    [image] Sample Code    [image]   Repair

Description

Your program attempted to access a file using a file number that is not currently associated with any open file.

Sample Code

...

Open "NEWVISIT.TXT" For Output As #1

Open "VISLIST.TXT" For Output As #2

Write #1, TheDate, Name, Comments

Close

...

' the preceding Close statement, used without specifying

' a file number, caused all open files to close

' Therefore, the following Write statement fails.

Write #2, TheDate, Counter

Close #2

Repair

Make sure that the file number represents a currently open file.  You may want to:

•	Check that the specified file number matches the one you used in the Open statement for this file.

•	Make sure your code includes a valid Open statement for the file.

•	Be sure that you did not accidentally use the Close statement without arguments, since this may close all open files, and invalidate file numbers.

Related topics in the Visual Basic help system include:

•	FreeFile function

•	Open statement

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Invalid argument: File number out of range

 Description    [image] Sample Code	   Repair

Description

Your program attempted to access a file using a file number that does not fall within the allowed range of 1 - 511.

Sample Code

For FileNumber = 0 To 5

' Since 0 is not within the allowed range for file numbers, an error

' occurs on the first iteration through this loop, at the Open statement.

Open "Test" & FileNumber For Output As #FileNumber ' Create a file.

Write #FileNumber, "This is only a test."  ' Output text.

Close #FileNumber   ' Close file.

Next FileNumber

Repair

Make sure that the file number falls within the allowed range of 1 - 511. If you wrote code to generate file numbers automatically, check that the code always produces valid numbers. You may want to use Visual Basic's FreeFile function to obtain file numbers.

Related topics in the Visual Basic help system include:

•	FreeFile function

•	Open statement

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Named argument to method x not found
Invalid argument: Item not found

Named argument to method methodname not found

 Description    [image]  Sample Code    [image] Repair

Description

Your program specified a named argument that does not match any of the named arguments defined for the method it is trying to invoke.

Sample Code

Dim MainButton

Set MainButton = Form1.Command1

Call MainButton.Move(Left:=7, Top:=10)

Repair

Check the spelling of the arguments, and review the method declaration.


Resource ID x not found
Invalid argument: Item not found

Resource ID ID not found

 Description    [image] Sample Code    [image] Repair

Description

Your program tried to load a resource using either the LoadResData, LoadResPicture, or LoadResString method, but passed an unrecognized ID to the given function.

Sample Code

...
' If ID 1000 does not exist in the StringTable.RES file,
' the following line results in an error

tmp = LoadResString(1000)

Repair

Check the spelling of specified ID, and be sure the appropriate resource files are included in your project.

Related topics in the Visual Basic help system include:

•	LoadResData function

•	LoadResPicture function

•	LoadResString function

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Invalid argument: Network path not allowed

 Description    [image] Sample Code    [image] Repair

Description

Your program specified a network path in a context where this is not allowed. For example, the ChDrive statement accepts only drive letters, not drive names. (If you pass a multi-character string to ChDrive, it uses only the first character of the string.)

Sample Code

' ChDrive uses only the first character
' of any string passed to it, which in this

' example evalutes to a "\". Since this is an
' invalid drive identifier; the
' statement results in an error

ChDrive "\\ADMIN\C-DRIVE"

Repair

Review how your program sets the given argument. You may also want to review the definition of the given statement in the Visual Basic Help system for descriptions of valid arguments.


Invalid argument: Empty variable not allowed

 Description    [image] Sample Code    [image] Repair

Description

Your program passed a variable containing an empty string or a variant variable that was never set to a value as an argument in a context where this is not allowed.

Sample Code

Dim EnvString
Dim EnvName
' Since the program did not set the variable EnvName
' the next line results in an error
EnvString = Environ(EnvName)

Repair

Review how your program sets the argument, and be sure that your logic prevents the value from ever being empty.


Invalid argument: Null variant value not allowed
Invalid argument: Null variant not allowed

 Description    [image] Sample Code    [image] Repair

Description

Your program passed a null variant as an argument in a context where this is not allowed.

Sample Code

Dim FY
Dim FYReportOptions

' FiscalYear, a function defined by the developer,
' gets the year from the input value
FY = FiscalYear("2/29/97")

' String returned by FiscalYear is used to
' get an environment variable, that
' has the options for this
' program.  However, year is set to Null
' due to an error inside FiscalYear,
' thus the Environ function fails.

FYReportOptions = Environ(FY)

...

Function FiscalYear(InputDate)

   Dim year

   ' Set up an error handler

   On Error GoTo ErrHandler

   ' Try to get the year from the date

   year = DatePart("yyyy", InputDate)

   ' Return the year we extracted

   FiscalYear = "FY" & year

   Exit Function

ErrHandler:

   ' Set the year to null to indicate it

   ' contains no valid data

   FiscalYear = Null

   Exit Function

End Function

Repair

Review how your program sets the argument, and be sure that your logic prevents the variant’s value from ever being null.


Invalid argument: Wildcards not allowed

 Description    [image] Sample Code    [image] Repair

Description

Your program included wildcards in a path specification in a context where this is not allowed.

Sample Code

' Since FileLen does not accept wildcarded arguments
' the following line generates an error
SizeOfLogFiles = FileLen("C:\MYLOGFILES\*.*")

Repair

Correct your path specification so that it no longer includes wildcard characters. Note that:

•	The error description identifies the position of the wildcard character (either asterisk or question mark).

•	Only a few Visual Basic statements, such as Dir and Kill, accept arguments that contain wildcard characters. You may want to review the definition of the statement you are using in the Visual Basic Help system.


Component creation failure

{Program Programname | DLL DLLname}  did not load (systemerror)

 Description    [image] Repair

Description

The specified component was found, but did not load.

Repair

Review the system error, reported at the end of the error description, for information on the cause of the failure.


Key x not found in registry
Component creation failure

Key keyname  not found in registry

 Description    [image] Repair

Description

This error generally indicates that the class name used in the program was recognized, but the class ID associated with the class was not found in the registry.

Repair

Re-register the component.

Note: When dealing with component-related errors, it is useful to have a general understanding of how Windows locates ActiveX components on your system. For some brief background information, see:

•	Windows Management of ActiveX Components: Background Information.


DLL x not found
Component creation failure

ActiveX {DLL DLLname | EXE exename}  not found

 Description    [image] Repair

Description

The DLL, OCX, or EXE containing the referenced component was not found in the directory specified in the registry.

Repair

Search for the named DLL, OCX, or EXE and move it to the appropriate location, or re-register it in it's current location.

Note: When dealing with component-related errors, it is useful to have a general understanding of how Windows locates ActiveX components on your system. For some brief background information, see:

•	Windows Management of ActiveX Components: Background Information.


Entry point identifier not found in library name
Component creation failure

Entry point identifier not found in library libraryname

 Description    [image] Repair

Description

The component is registered, but the DLL containing the component has not exported all the appropriate entry points for the component.

Repair

Add the specified entry point to the DEF file used to link the DLL.

Note: When dealing with component-related errors, it is useful to have a general understanding of how Windows locates ActiveX components on your system. For some brief background information, see:

•	Windows Management of ActiveX Components: Background Information.


Object x not found in registry
Component creation failure

Class classname  not registered

 Description    [image] Sample Code    [image] Repair

Description

The specified class name was not found in the registry.

Sample Code

' If Excel is not installed on the system, the
' following code results in an error
Dim app
Set app = CreateObject(“excel.application”)

Repair

Check the spelling of the class name. When referencing a component that may not be present on all systems that run your program, use an error handler to manage program behavior when the component is absent.

Note: When dealing with component-related errors, it is useful to have a general understanding of how Windows locates ActiveX components on your system. For some brief background information, see:

•	Windows Management of ActiveX Components: Background Information.


Windows Management of ActiveX Components: Background information

Windows uses a sequence of steps to uniquely identify components, and map their location on your system. When a problem related to accessing ActiveX components occurs the error description helps you quickly correct it by pinpointing the error to the specific step in this sequence that failed. Understanding this sequence can help you quickly correct component-related errors.

The mapping sequence for a component is always:

1) Class Name
-> 2) Class ID
   -> 3) component path
      -> 4) the component itself

1	Class Name, which is assigned by the component's author, is used to identify the component when registering or retrieving it. (Note that programmatic ID is another term used for Class Name.)

A sample Class Name is: Word.Document

Notes: Generally components come with installation scripts which automatically register them. When a script is not available, you can use the Windows REGSVR32 program to register an ActiveX DLL. To register an ActiveX EXE, run the program with the /REGISTER switch.

2	Class ID is a 128 bit number that uniquely identifies the component and is generated by the author of the component.

Note When you author a component in the Visual Basic development environment, Visual Basic automatically generates the Class ID for it.

3	path+component name is the location and file name of the DLL, exe or OCX file that contains the component. For example:

C:/Msoffice/Winword/Winword.exe

4	the component itself is the actual DLL, exe or OCX. Note that it is important to make a distinction between the path+component name described in step 3, and the component itself. In some instances, an error may result when there is a Registry entry for the component that correctly maps a Class Name to Class ID to a location and program name, but the program itself is either missing or unable to load for some reason.

Also See

•	Finding Data in the Windows Registry

Related topics in the Visual Basic help system include:

•	CreateObject

•	GetObject

 (After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Finding Data in the Registry
Finding Data in the Windows Registry

One way to solve component-related problems is to examine the Windows Registry directly. Using the Windows Registry Editor, you can look up component-related information, including Class Name, Class ID, and associated path and file information.

This section shows the organization of information in the Registry. It uses a sample sequence of steps to look up the information associated with a given Class Name.

1	Start the Registry Editor, Regedit.exe, located in the Windows directory.

The Editor window displays Registry information within a standard Windows folder hierarchy.

2	Class Names are stored under HKEY_CLASSES_ROOT. For example, if you were looking up the Class Name “Excel.Application”, you would find it in the alphabetical listing of class names under HKEY_CLASSES_ROOT. (You can either scroll through entries or use the Find option on the Edit menu to locate items in the Registry.)

3	The Class ID associated with the Class Name is stored in a CLSID sub-folder under the Class Name’s folder. When you double-click on CLSID, you will see the Class ID in the right-hand pane of the Registry Editor window.

4	Make a note of the Class ID then return to the top-level folders in the Registry Editor window. One of these folders is the main Class IDs folder, CLSID, which contains entries for all Class IDs. Under CLSID find and open the folder for the Class ID you want to examine.

5	One of the subfolders under the Class ID should be either:

•	LocalServer32, in which the location and name of the application file (EXE) associated with a Class ID is stored, or

•	InProcServer32, in which the location and name of the DLL or OCX associated with a Class ID is stored

When you double-click on either LocalServer32, or InProcServer32, you will see the component path and file name in the right-hand pane of the Registry Editor window.

Here is the LocalServer32 folder for the Class ID.

And the path and file name entry for the excel application:


File specification x contains an error
File access failure

filespec  contains an error (systemerror)

 Description    [image] Repair

Description

A file specification in your program did not correctly identify a file on your system.

In most instances, SmartCheck is able to pinpoint the source of file access problems, and will display a detailed error message. The current error appears when SmartCheck is not able to identify the exact cause of the file access failure.

Repair

Review the reported system error for more detailed information about the problem.


Cannot move directory directoryname to another drive drivename
File access failure

Cannot move directory directoryname to another drive (drivename)

 Description    [image] Sample Code    [image] Repair

Description

Your program tried to move a directory from one drive to another using the Name As statement. You can move individual files, but not directories, between drives with Name As.

Sample Code

OldName = "C:\DIR1"
NewName = "E:\DIR2"

Name OldName As NewName

Repair

•	If you did not intend to move a directory across drives, review how your program sets arguments for the Name As statement. Be sure it never permits a combination of arguments that would result in this operation.

•	If you do need to move directories across drives, one approach is to write a loop in which you use the DIR function to retrieve each file, in turn, in a given directory, then move it to the specified drive. Here is an example (it assumes that the directory “E:\DIR2” already exists).

' Make "CurrentFile" the first filename in

' the "C:\DIR1" directory.

CurrentFile = Dir("C:\DIR1\*.*", vbNormal)

' While there are files remaining

Do While Len(CurrentFile) > 0
' Prefix file name with old path name

    OldName = "C:\DIR1\" & CurrentFile

' Prefix file name with new path name

NewName = "E:\DIR2\" & CurrentFile

' Move file from current directory to new directory

Name OldName As NewName
' Get next file to be moved

CurrentFile = Dir '

Loop

Related topics in the Visual Basic help system include:

•	Name statement

•	Dir function

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Cannot execute name
File access failure

Cannot find {program programname | dll dllname}

 Description [image] Sample Code [image] Repair

Description

The program name that your program passed as an argument to the Shell function could not be found or the Declare statement named a DLL that was not found.

Sample Code

Dim RetVal
' A spelling error in
' the following statement results in
' the “Cannot find…” error
RetVal = Shell("C:\WIMDOWS\CALC.EXE", 1)    ' Run Calculator.

Repair

You may want to check the spelling of the program name. You may also want to check and/or set the PATH environment variable to make sure that it includes the path to the specified file.You can use:

•	the Visual Basic Environ function to retrieve the current value of the PATH variable

•	The Windows API SetEnvironmentVariable function to set the PATH variable

Related topics in the Visual Basic help system include:

• στατεμεντ!Klink(“Shell statement”,1)

•	Environ function!Klink(“Environ function”,1)

•	Declare Statement!Klink(“Declare statement”,1)

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Cannot use functionname with a file that was opened with modetype  access mode
File Access Failure

Cannot use functionname with a file that was opened with modetype  access mode

 Description    [image] Sample Code    [image] Repair

Description

The operation specified in the error description failed, because the file was opened with an access mode which prohibits the given operation.

Sample Code

Dim FileNum As Integer

Dim Var1

FileNum = FreeFile

Open "FINANCE.DAT" For Random As FileNum

Input #FileNum, Var1

Repair

•	If your program opened the file, review the access modes you specified when opening the file.


File Access Failure

{Program programname | DLL DLLname}  did not load (systemerror)

 Description    [image] Repair

Description

The specified DLL, or EXE, was found, but did not load.

Repair

Review the system error, reported at the end of the error description, for information on the cause of the failure.


Path path specified to function already exists
File system object already exists

Path "pathspec" specified to "functionname" already exists

 Description    [image] Sample Code    [image] Repair

Description

Your program tried to create a directory (for example, using the MkDir function) but the specified directory already exists.

Sample Code

' If the "c:\windows" directory already
' exists, the line below will generate an
' error.
MkDir "c:\windows"

Repair

You can use Visual Basic's Dir function to check whether or not a specified directory name already exists before attempting to create a directory with that name, as shown by this sample code:

' the "Dir" function is used to test
' whether a specified directory already exists
' before attempting to create it.

If Len(Dir("c:\windows", vbDirectory)) = 0 Then
' there is no existing "Windows" directory,
' therefore, create it.
    MkDir "c:\windows"
Else
    MkDir "c:\windows2"

' Above line assumes Windows2
' does not also exist.

End If

A related topic in the Visual Basic Help system:

•	Dir function

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


name is in use by another process
File access failure

filename is in use by another process

 Description    bmc Button.bmp} Repair

Description

A file your program tried to open is currently in use by another process that has set sharing permissions to prevent concurrent access.

Repair

Write an error handler to anticipate and manage this circumstance.


File access failure: No permission to access file

 Description       [image] Sample Code    [image] Repair

Description

The current permission settings on a file or directory prevented your program from completing an attempted operation. For example, your program tried to open a read-only file for writing, or to delete a read-only file or directory.

This error may result either from permissions options set under the Security tab in the Windows explorer program, or the read-only file setting under the general Properties for the file.

Sample Code

Dim prog As String

Dim hFile As Long

Dim ret As Long

prog = "c:\test.txt"

hFile = CreateFile(prog, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)

Open prog For Output As #1

ret = CloseHandle(hFile)                'close  temp file

Kill prog                               'remove temp file

Repair

You may want to:

•	Check that your program is acting on the intended file or directory.

•	Use Visual Basic’s GetAttr function to check whether a file is set to be read-only before attempting to write to it.

•	If appropriate, use Visual Basic’s SetAttr statement to change the read-only attribute on the target file or directory.


Drive name does not exist
File access failure: Cannot find specified file system object

Drive drive does not exist

 Description [image] Repair

Description

The drive portion of a path specified by your program is incorrect. For example, if this error occurs when a program tries to retrieve the current directory of drive Q, it indicates that Q is not a local drive or a mapped network drive.

Repair

•	Check and correct the drive portion of the path specified by your program.

•	You can use two Windows API functions, GetLogicalDriveStrings and GetDriveType, to obtain a list of available drives, and to identify the type of a given drive, as shown in this example:

Private Sub Command1_Click()

    Dim drives As String

    Dim resLen As Long

    Dim thisDrive As String

    Dim pos As Long

    Dim newPos As Long

    Dim driveType As Long

    Dim driveTypeString As String

    drives = Space$(1024)

    resLen = GetLogicalDriveStrings(Len(drives), drives)

    pos = 1

    While (pos - 1 < resLen)

        newPos = InStr(pos, drives, Chr$(0))

        thisDrive = Mid(drives, pos, newPos - pos)

        driveType = GetDriveType(thisDrive)

        driveTypeString = driveTypeName(driveType)

        List1.AddItem (thisDrive & " " & driveTypeString)

        pos = newPos + 1

    Wend

End Sub

Private Function driveTypeName(ByVal driveType As Long) As String

    Select Case driveType

        Case 0:

            driveTypeName = "Unknown"

        Case 1:

            driveTypeName = "Not found"

        Case DRIVE_CDROM:

            driveTypeName = "CD-Rom"

        Case DRIVE_FIXED:

            driveTypeName = "Fixed"

        Case DRIVE_RAMDISK:

            driveTypeName = "Ram disk"

        Case DRIVE_REMOTE:

            driveTypeName = "Remote"

        Case DRIVE_REMOVABLE:

            driveTypeName = "Removable"

        Case Else

            driveTypeName = "Unknown"

        End Select

End Function


Network node node not found
File access failure: Cannot find specified file system object

Network node nodename not found

 Description [image] Repair

Description

The computer named in a path was not found. For example, if this error occurs as a result of this path specification:

\\ORANGE\C-DRIVE\UserA\Report1.Doc

it indicates that the network computer "ORANGE" is not active, or doesn't exist.

Repair

Check and correct the computer named in the path.


Path path not found
File access failure: Cannot find specified file system object

filename not found

 Description [image] Repair

Description

Your program could not find a file it was attempting to open.

Repair

Review and correct the drive, directory and filename identified in the given path specification.


Network share sharename not found
File access failure: Cannot find specified file system object

Network share sharename not found

 Description [image] Repair

Description

The drive specified in a path was not found as a shared resource. For example, if this error occurs as a result of this path specification:

\\ORANGE\C-DRIVE\UserA\Report1.Doc

it indicates that the network machine "ORANGE" is active, but that it does not contain a network-share C-DRIVE.

Repair

Check that your program is targeting the drive you intended and that network sharing is active for that drive.


Source path pathname or destination path pathname not found
File access failure: Cannot find specified file system object

Source path pathname or destination path pathname not found

 Description [image] Repair

Description

The program tried to rename a file using the Name statement, but either the source path or the destination directory was not found.

Repair

Check that both the source and destination specifications are valid.


filename already open
File access failure: File already open

filename is already open

 Description    [image] Repair

Description

The file name that your program passed as an argument to the Open statement identified a file that is in use.

Repair

Review previous operations performed by your program on this file, and be sure they were concluded properly and the file closed, as necessary.

Related topics in the Visual Basic help system include:

•	Open statement

•	Close statement

•	FreeFile function

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


File number filenumber already open
File access failure: File already open

File number filenumber already open

 Description [image] Repair

Description

The file number that your program passed as an argument to the Open statement identified a file number that is already open.

Repair

Review previous operations performed by your program on this file number, and be sure they were concluded properly and the file closed, as necessary.

Related topics in the Visual Basic help system include:

•	Open statement

•	Close statement


File access failure: No disk in drive

 Description    [image] Repair

Description

A floppy drive, specified in either the source or destination path for an operation by your program, does not contain a disk.

Repair

Make sure all referenced drives contain disks.


File access failure: Inappropriate wildcard match

 Description    [image] Repair

Description

Your program passed a file name value, containing wildcards, as an argument to a function or statement; the wildcarded value matched one or more files or directories, but none of those files were appropriate for the operation.  For example, your program attempted to delete files that were read-only.

Repair

•	If possible, check the relevant attributes of files that match the wildcarded values to ensure that they are appropriate for the given operation, before attempting it.

•	Write an error handler to anticipate and manage this circumstance.


Attempted to write #bytes to #bytes record
File read/write failure

Attempted to write #bytes to #bytes record

 Description    [image] Sample Code    [image] Repair

Description

The total length of the variable(s) used to write data to a record must be less than or equal to the length specified in the Open statement for the given file.

Sample Code

Dim myData As String

myData = "Hello world"

Open "Database.dat" For Random As 1 Len = 8

Put #1, 1, myData

Repair

Be sure that you understand the sum total size of all the variables you are writing to a record.

This error can sometimes result from not understanding the storage overhead associated with certain data types. For example:

•	Visual Basic adds a 2-byte descriptor to any variable-length string placed in a random access file with Put. Therefore when writing a variable-length string, you must be sure that it is at least 2 characters shorter than the record length specified in the Len clause of the file's Open statement

•	A variant requires a 2-byte descriptor. Therefore when using a variant, you must be sure that the value it holds is at least 2 bytes shorter than the record length specified in the Len clause of the file's Open statement.

•	Given the two preceeding statements, if you were to use a variant to write a variable-length string, that string would need to be at least 4 bytes shorter than the record length specified in the Len clause of the file's Open statement.


Invalid record number (recordnumber) passed to name statement
File read/write failure

Invalid record number (recordnumber) passed to name statement

    Description    [image]    Repair

Description

Record numbers that are less than or equal to zero are invalid with the Get or Put statement.

Repair

Check the logic that your program uses to generate the record number, and be sure that it never results in a negative or zero value. Be sure the variables you use to generate or hold the record number are spelled correctly. Unless your module includes an Option Explicit statement, any misspelled variable name will implicitly be declared and initialized to zero.


Control array element name does not exist
Invalid array operation

Control array element index does not exist

 Description    [image] Repair

Description

Your program specified an index that does not match any of the indices in the given control array.

Repair

Check the actual number of elements and their index values in the array.

Note  If you add or remove items from a control array when designing your application, Visual Basic does not automatically update the array indices. In other words if you create a four element array, then remove element 2, the index numbers for the remaining elements will be 1, 3, and 4; they will not be automatically updated to 1, 2, 3. Therefore it is a good practice to update a control array’s Index property manually, as necessary,  in design-mode, so that the indices remain sequential and contiguous.


Cannot retrieve Index property for name, it is not a control array
Invalid array operation

Cannot retrieve Index property for name, it is not a control array

 Description    [image] Repair

Description

You attempted to retrieve the Index property for an item that is not a control array. Only control arrays have the Index property.

Repair

Check the spelling and the data type of the item identified in the error description.

A related topic in the Visual Basic help system:

•	Control Arrays

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Must specify index for property array arrayname [of objectname]
Invalid array operation

Must specify index for property array arrayname [of objectname]

 Description    [image] Sample Code    [image] Repair

Description

Your program tried to reference a member of an array without specifying an index.

Sample Code

...
Dim theListBox

Dim Favorite

Set theListBox = List1

Favorite = theListBox.List
...

Repair

Specify an index to identify the array member to which you want access.


name is not a property array [of objectname]
Invalid array operation

name is not a property array [of objectname]

 Description    [image] Repair

Description

Your program specified an index for an item that is not a property array.

Repair

Check the spelling and data type of the variable identified in the error description.


Control array element name does not exist
Invalid array operation

Index indexnumber is out of range

 Description    [image] Repair

Description

Your program specified an index that does not match any of  the elements in a given array.

Repair

Review how your program is assigning the index value identified in the error description.


formname cannot be moved|sized while minimized|maximized
Invalid form operation

formname cannot be moved|sized while minimized|maximized

{bmc Button.bmp Description     [image]  Sample Code     [image]  Repair

Description

Visual Basic does not permit a form to be moved or resized when the form window is in either a minimized or maximized state.

Sample Code

If this code executes when the form “frmMain” is either maximized or minimized, an error occurs.

...
frmMain.Height = frmMain.Height - 100
...

Repair

•	One way to avoid this error is to set the form’s MaxButton and MinButton properties to False at design time, thus preventing the user from ever maximizing or minimizing it.  (Note that MaxButton and MinButton properties may not be altered at run time.)

•	You can check a form’s WindowState property to determine if it is either minimized or maximized before attempting to resize it in code.

Related topics in the Visual Basic help system include:

•	MaxButton Property

•	MinButton Property

•	WindowState Property

(After viewing a topic in the Visual Basic help system, click Help Topics to return to the SmartCheck help contents.)


formname cannot be moved|sized while minimized|maximized
Invalid form operation

Cannot show formname while modal form is active

{bmc Button.bmp Description     [image] Sample Code     [image] Repair

Description

Your program attempted to display a form when a modal form was already active, which is an invalid action in Visual Basic.

Sample Code

...
frmModalTest.Show vbModal

...

' the following code, attached to a command

' button in the frmModalTest form, results in an error

Private Sub cmdOpenForm_Click()

frmNowMe.Show

End Sub

Repair

Review and re-write your code to close the modal form before attempting to open another form.

A related topic in the Visual Basic help system:

•	Show method

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Wrong number of arguments when getting Value property for conversion to datatype
Invalid object reference

Wrong number of arguments when getting default property for conversion to datatype

 Description    [image] Sample Code    [image] Repair

Description

An attempted assignment operation failed, because your program did not specify the correct number of arguments for the object on the right-side of the statement, to obtain its default property, or invoke its default method.

Sample Code

Dim MyColl

Set MyColl = New Collection

MyCount = MyColl

Repair

If you intended to assign an object reference, rather than to retrieve a property value, using the given statement, see Invalid object references: Background information. If you did intend to retrieve the default property, review the object definition for a description of arguments and syntax.


Invalid object references: Background information

One common cause of errors related to object references is using statements incorrectly, causing unintended operations. For example, this code creates a collection object, and correctly establishes a reference to that object:

Dim FavoritesObject

Dim ChoicesObject as New Collection

Set FavoritesObject = ChoicesObject ' Assigns object reference.

This code, however, does not:

Dim FavoritesObject

Dim ChoicesObject as New Collection

FavoritesObject = ChoicesObject ' incorrect assignment

Instead, the last statement above attempts to assign the default property of the object named on the right side of the statement to the variable on the left side. If this were the intended action, an argument to the ChoicesObject would be necessary to identify which item in the Collection object was to be retrieved for the assignment operation. Since this argument is not provided, an error results.


Invalid object reference

 Description    [image] Sample Code    [image] Repair

Description

Your program attempted to reference an object, but the object variable on which it acted has no object assigned to it. The second line of the error description describes the specific action you attempted. See Repair, below, for more information.

Sample Code

Dim MyObj As Object
Dim MyStr
MyStr = MyObj.Caption

Repair

Use the second line of the error description to isolate the cause of the error:

•	Cannot change property propertyname, no object assigned to object variable

•	Cannot retrieve property propertyname, no object assigned to object variable

•	Cannot call method methodname, no object assigned to object variable

•	Property or method propmethodname not available, no object assigned to object variable

•	Cannot set property propertyname to reference object, no object assigned to object variable

For any of these conditions, review how your program is setting the given variable, and correct your code to ensure that an appropriate object assignment occurs.


name is not a property that holds references for [this object | objectname]
Invalid object reference

name is not a property that holds references for {this object | objectname}

 Description    [image] Sample Code    [image] Repair

Description

Your program tried to assign an object reference to a property that is not able to hold object references.

Sample Code

Dim MyForm
Set MyForm = Form1
' The following line results in an error
Set MyForm.Tag = Form1.Command1

Repair

You may want to review:

•	the definitions of the objects and properties you are using.

•	the definition of the Set statement in the Visual Basic help system. (After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


method call not valid for itemname
Invalid object reference

method call not valid for name

 Description    [image] Sample Code    [image] Repair

Description

The item specified in the error description is either a valid property or method for the given object, however, the attempted method call was an invalid operation for the given item.

Sample Code

Dim MyForm As Variant

Set MyForm = Form1

Call MyForm.Width(2)

Repair

You may want to review the definitions of the methods or properties for the object you are using.


Get or Put operation not valid for itemname
Invalid object reference

{Get | Put} operation not valid for itemname

 Description    [image] Sample Code    [image] Repair

Description

The item specified in the error description is either a valid property or method for the given object, however, the attempted Get or Put was an invalid operation for this item.

Sample Code

Dim MyTextBox

Dim CurrentValue

Set MyTextBox = Form1.Text1

' MyTextBox is a text box array,

' not a text box, therefore, the

' following code results in an error

CurrentValue = MyTextBox.Text

Repair

You may want to review the definitions of the methods or properties for the object you are using.


Wrong number of arguments when {changing | setting a reference for} propertyname  property
Invalid object reference

Wrong number of arguments when {changing | getting | setting a reference for} propertyname  property
Wrong number of arguments when calling methodname method

 Description    [image] Sample Code    [image] Repair

Description

An attempted assignment operation failed, because your program did not specify the correct number of arguments for the object on the right-side of the statement when changing, getting or setting a reference for a given property, or when calling a given method.

Sample Code

Dim MyCtl

Set MyCtl = Form1.Command1

Call MyCtl.ShowWhatsThis(True)

Repair

If you intended to assign an object reference, rather than to perform any of the operations mentioned above, see Invalid object references: Background information below. If you did intend to perform one of the stated operations, review the object definition for a description of arguments and syntax.

Note: In general, it is good programming practice to use “early binding” rather than “late binding” of objects, so that mistakes involving object types will be caught at compile-time, rather than runtime. Declarations that assign specific object types to variables result in early binding. Declarations that simply create variables that are of the general type “object” result in late binding.


name is neither a property nor method for {this object | objectname}
Invalid object reference

name is neither a property nor a method for {this object | objectname}

 Description    [image]  Sample Code    [image] Repair

Description

A name specified by your program was neither a valid property nor method for the referenced object. The referenced object may be of a different type than you are assuming or you may have mis-typed the name.

Sample Code

Dim CurrentObject

...

' This following line sets CurrentObject to a Timer object
Set CurrentObject = myTimer

...

' Since Caption is neither a property nor a method
' of the timer object, the following line results in an error

CurrentObject.Caption = "I'm A Timer"

Repair

Check the object type, and the spelling of the name. If you are referencing the intended object type, review the definition of the object’s properties and methods.

Note: In general, it is good programming practice to use “early binding” rather than “late binding” on objects, so that mistakes involving object types will be caught at compile-time, rather than runtime. Declarations that assign specific object types to variables result in early binding. Declarations that simply create variables that are of the general type “object” result in late binding.


Property name [of objectname] cannot be changed from an ActiveX DLL or control
Invalid object reference

Property name [of objectname] cannot be {retrieved|changed} from an ActiveX DLL or control

 Description    [image] Sample Code    [image] Repair

Description

Your program attempted an operation that is not valid from an Activex DLL or control.

Sample Code

' inside a method called "MyMeth1" in an ActiveX DLL

Public Function MyMeth1() As Variant
   MyMeth1 = mvarMyProp1
   Dim TheApp, IsTaskVisible
   Set TheApp = App

   On Error Resume Next
   IsTaskVisible = TheApp.TaskVisible
End Function

Repair

These operations are not valid from within an ActiveX DLL or control:

•	Setting the LinkMode property of a form or control.

•	Setting or retrieving the App.TaskVisible property.

•	Setting or retrieving the App.OleRequestPendingTimeout property.

•	Setting or retrieving the App.OleServerBusyRaiseError property.

•	Setting or retrieving the App.OleServerBusyTimeout property.

•	Setting or retrieving the App.OleServerBusyMsgTitle property.

•	Setting or retrieving the App.OleServerBusyMsgText property.


Registry entry not found

 Description    [image] Sample Code    [image] Repair

Description

The combination of application and section name values supplied as arguments to a registry-related function did not match an existing entry in the registry.

Sample Code

DeleteSetting “MyApp”, “User Preferences”

Repair

•	Check your code to be sure you have identified, and spelled, the application and section names correctly.

•	Include an error handler to manage the program’s behavior when this error occurs.


Conversion Failure

 Description    [image] Repair

Description

Your program attempted an invalid data conversion.

In most instances, SmartCheck is able to pinpoint the source of conversion problems, and will display a detailed error message. The current error appears when SmartCheck is not able to pinpoint the exact cause of the conversion failure.

Repair

Check your code for possible causes, such as inappropriate value assignments using variants, that may have resulted in this error.


Property propertyname [of object objectname] set to an out of range value [(value)]
Invalid property value

Property propertyname [of object objectname] set to an out of range value [(value)]

 Description    [image] Sample Code    [image] Repair

Description

Your program attempted to assign a property value that was not within the allowed range for that property.

Sample Code

Only 0, 1 and 2 are valid values for WindowState, therefore, this code results in an error.

frmMain.WindowState = 3

Repair

Review the Visual Basic definition for the property you are using. Check your code to determine how you specified, or obtained, the property value, and ensure that your logic prevents out-of-range values from ever being assigned.


Object required to set the propertyname property of {this object | objectname}
Invalid property value

Object required to set the propertyname property of {this object | objectname}

 Description    [image] Sample Code    [image] Repair

Description

The variable on the right hand side of a Set statement that is trying to set a property, is not an object.

Sample Code

Dim Italics

Dim MyForm

Set MyForm = Form1

' Italics was not set to anything, therefore it is an
' empty variant, and the following line results in an error.
Set MyForm.Font = Italics

End Sub

Repair

Review how your program is setting the values of the variables used in the Set statement.


Type mismatch

 Description    [image] Sample Code    [image] Repair

Description

Your program attempted an invalid data type conversion.

Sample Code

This code fails because it leaves out the first argument (the position at which to start searching a string) to the InStr function. The first argument is normally optional, but is required when the compare argument (vbTextCompare, in this case) is present.

Pos = InStr("Where am I?", "I", vbTextCompare)

Repair

One common source of conversion errors in Visual Basic is the incorrect use of variants. You must always ensure that a variant’s value is appropriate to the context in which it is being used. For example, if your program uses a variant to pass a text string to a function that manipulates dates, you must be sure that the string is always properly formatted as a date value, or errors will occur.


Destination file filename already exists
File system object already exists

 Destination file filename already exists

 Description    [image] Repair

Description

Your program attempted to rename a file, using the Name As statement, but the destination file name already exists.

Repair

Before attempting to rename a file, check that the specified name does not already exist, or write an error handler to anticipate and manage this circumstance. You can use the Dir function to check for the existance of a file.

Related topic in the Visual Basic help system:

•	Dir function

(After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.)


Destination file filename already exists
File access failure

 Attempting to move pathspec to pathspec (systemerror)

 Description    [image] Repair

Description

Your program failed while attempting to move a file from one location to another on your system using the Name As statement.

In most instances, SmartCheck is able to pinpoint the source of file access problems, and will display a detailed error message. The current error appears when SmartCheck is not able to identify the exact cause of a file access failure that occurred as a result of a Name As statement.

Repair

Review the reported system error for more detailed information about the problem.


Empty string not allowed for pathname argument to functionname
Invalid argument: Bad path

Empty string not allowed for pathname argument to functionname

 Description    [image] Sample Code    [image] Repair

Description

Your program passed an empty string rather than the path specification expected by a given function.

Sample Code

...

ChDir  “ ”
...

Repair

Review the definition of the function identified in the error description.


function functionname is not exported from DLLname
Invalid function declaration

function functionname is not exported from DLLname

 Description    [image] Sample Code    [image] Repair

Description

The function named in a declaration statement was not found in the specified dll.

Sample Code

...

' A spelling error in the function name results in an error
Declare Sub GetSystmInfo Lib "kernel32" (lpSystemInfo As SystemInfo)

...

Repair

Make sure that the function exists in the library and the function name is spelled correctly.


Pattern string stringspec does not have matching brackets
Invalid pattern string

Pattern string stringspec does not have matching brackets

 Description    [image] Sample Code    [image] Repair

Description

A bracket character is missing from a statement using the Like operator.

Sample Code

IsThere = "O" Like "[M-T"

Repair

Fix the syntax.


Path pathspec to object not found
Component creation failure

Path pathspec to object not found

 Description    [image] Sample Code    [image] Repair

Description

The path name specified as the second argument to the GetObject function was not found.

Sample Code

Dim Obj
' If the file MyReport.doc is not present,
' this code results in an error
Set Obj = GetObject(path: = “C:\MyReport.doc”)

Repair

Review how your program obtains the value for the second argument.


Index must be specified for object array arrayname [of object objectname]
Invalid array operation

Must specify index for object array arrayname [of object objectname]

 Description    [image] Repair

Description

Your program attempted to reference a member of an array without specifying an index.

Repair

Review and correct the reference in your code.


Property propertyname [of object objectname] is not an object array
Invalid array operation

Property propertyname [of object objectname] is not an object array

 Description    [image] Repair

Description

Your program attempted to reference an item as though it were a member of an object array, but it is not.

Repair

Review and correct the reference in your code.


Cannot change dimensions of array when using Preserve keyword
Invalid array operation

Cannot change number of array dimensions when using Preserve keyword

 Description    [image] Sample Code    [image] Repair

Description

A statement that contains the Preserve keyword cannot be used to change the number of dimensions defined for an array.

Sample Code

Dim MyArray() As Integer

ReDim MyArray(5, 5, 5)

For x = 1 To 5

    For y = 1 To 5

        For z = 1 To 5

        MyArray(x, y, z) = 1

        Next z

    Next y

Next x
' The next line results in an error because it attempts to
' change # of array dimensions while using Preserve keyword

ReDim Preserve MyArray(5, 5)

Repair

You may want to review the description and sample uses of the Preserve keyword under the ReDim Statement topic in the Visual Basic help system.


Cannot change lower boundary of array when using Preserve keyword
Invalid array operation

Cannot change lower boundary of array when using Preserve keyword

 Description    [image] Sample Code    [image] Repair

Description

A statement that contains the Preserve keyword cannot be used to change the lower boundary defined for any dimension of an array.

Sample Code

Dim MyArray() As Integer

ReDim MyArray(2 To 5, 5, 5)

For x = 1 To 5

    For y = 1 To 5

        For z = 1 To 5

        MyArray(x, y, z) = 1

        Next z

    Next y

Next x
' The next line results in an error because it attempts to
' redefine lower bound of the first dimension while
' using Preserve keyword

ReDim Preserve MyArray(1 To 5, 5, 5)

Repair

You may want to review the description and sample uses of the Preserve keyword under the ReDim Statement topic in the Visual Basic help system.


Cannot set Caption property of menuname to '-'.
Invalid operation

Cannot set Caption property of menuname to '-'.  The menu is a parent or has a shortcut key associated with it.

 Description    [image] Sample Code    [image] Repair

Description

Visual Basic does not permit you to assign the separator bar, “-“, as the Caption value for a menu item that is either a parent (i.e., has submenus), or has a shortcut key assigned to it.

Sample Code

' Assuming mnuFile is a parent
' menu, the following statement fails

Form1.mnuFile.Caption = "-"

Repair

Correct the definition of the menu’s Caption property.


Cannot set Visible property of menu item menuname from parent menu
Invalid operation

Cannot set Visible property of menu item menuname from parent menu

 Description    [image] Sample Code    [image] Repair

Description

Visual Basic does not permit you to set a menu’s Visible property from a parent menu.

Sample Code

' mnuOpen is an item on the mnuFile menu,
' therefore, this code results in an error

Private Sub mnuFile_Click()

 Form1.mnuOpen.Visible = False

End Sub

Repair

Move the code you are using to set the Visible property, so that it is not run from the parent menu.


Function functionname in DLLname was not called correctly
Invalid function declaration

Function functionname in DLLname was not called correctly

 Description    [image] Sample Code       [image] Repair

Description

Your program did not supply the appropriate arguments, or otherwise specified incorrect syntax, when calling the function identified in the error description.

Note that this error only appears when you run a program that was compiled to P-code.

Sample Code

Private Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" (ByVal drive As String, bufLen As Long) As Long

...

Sub Main()

   Dim driveType As Long

   Dim driveName As String

   driveName = "C:\"

   driveType = GetDriveType(driveName, 7)

End Sub

Repair

Review the function definition.


SmartCheck analysis not yet available

Your program has encountered an error for which there is, as yet, no SmartCheck analysis. If you would find a SmartCheck analysis of this type of error useful, please send our technical support staff information on how to reproduce it.

We will review your information and consider implementing analysis of the error in a future SmartCheck release.

General debugging tips

•	If you encountered a problem in a control, written in C, you may want to examine the C++ header file, winerror.h, to find the failure status name, then look for references to that name in the Visual C++ online help or documentation.

•	When debugging a particularly hard-to-solve problem, use SmartCheck options to obtain the most detailed information possible on program events. Reviewing the SmartCheck log of these events will help you analyze the error yourself.:

1	On the Program menu, click Settings; on the Error Detection tab, click Advanced; Under Performance Optimizations (at the bottom of Advanced Settings), disable the setting to Suppress system API and OLE calls.

2	Re-run your program to have SmartCheck include system API and OLE calls in its logging of your program events.

3	After running your program, click the yellow icon in the SmartCheck toolbar to display a detailed, expanded view of events and calls that led to your error.

•	Review information in the Visual Basic help system on Trappable errors. After viewing a Visual Basic topic, you can click Help Topics at the top of the Visual Basic Help window to return to the SmartCheck help contents.


Array index out of range

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when an illegal value is used to index an array. This is a common error that can be difficult to detect, especially if the out-of-range elements have zero values.

Sample Code

Because of an incorrect loop range, the following code tries to access an illegal array element:

int h[10];

...

int i, tot=0;

for (i=0; i<=10; i++)

tot += h[i];

...

Repair

This error is frequently caused by incorrect initialization or termination, such as in the above sample code. The following shows the repaired code:

...

int i, tot=0, h[10];

for (i=0; i<sizeof (h)/sizeof (h[0]); i++)

tot += h[i];

...


  Assigning pointer out of range

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when you copy a pointer that is not within a valid range. Although this is not a critical error, it may indicate logic problems in your code that could cause other errors.

Sample Code

The following code shows an example of  this error. The first line of code initializes an array of  10 chars. The subsequent line assigns pointer z to an unallocated area, which creates the out-of-range condition.

...

char *x, *z;

x = new char [10];

z = x + 20;

...

Repair

The best solution for this error is to copy only valid pointers. To find the potential cause of an invalid pointer, examine the boundary cases in your code.


  Expression uses unrelated pointers

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when an expression compares pointers that point to different memory blocks. This only applies to the >, >=, <, and <=  operators (the operators == and != are exempt).

This construct is considered undefined in the ANSI C-language specification, except when a pointer points to an object one beyond the end of a block.

Sample Code

The following shows sample code that compares unrelated pointers:

...

char c[10], *d;

d = (char *)malloc(10);

if (c > d)

    c[0] = 'x';

else

    c[0] = 'y';

...

The error in the above sample is:

if (c > d)

    c[0] = 'x';

because it tries to compare pointers that point to different memory blocks (an undefined operation according to the ANSI C specification).

Note that in the above sample, it does not matter that c and d are different data types.

Repair

The solution for this problem is to avoid using this construct, since it is undefined in ANSI C.
However, this construct is supported on many systems and frequently used.


  Expression uses dangling pointer

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur in an expression operated on a dangling pointer, which points to either: a dynamically allocated memory block that has since been freed or an allocated memory block that has returned to the stack.

Sample Code

The following sample code allocates a memory block, then frees (deallocates) that block. The error occurs after the memory is freed, because the pointer f now points to an invalid (unallocated) memory block.

...

char *f = (char *)malloc(10);

char g[10];

free(f);

if (f > g)

f = g;

...

Repair

A common cause of this problem is the use of a wrong pointer in the expression, so you should examine the expression to verify that the appropriate pointer was used. If the pointer is accurate, review the code that deallocated memory to ensure memory was freed properly.


  Function pointer is not a function

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when an invalid pointer is used to call a function.

Sample Code

The following code shows an example of this error using the union data type. The error occurs because the union calls a function pointer after initializing another union member.

union {

int *iptr;

int (*fptr) ();

} u;

...

int i;

u.iptr = &i;

u.fptr();

...

Repair

To repair this error, look for and fix any incorrect function pointer statements in the referenced memory block.


  Memory leaked due to free

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when a pointer in a memory block points to another dynamically allocated memory block, creating a permanent memory leak.

Sample Code

The following sample code creates and allocates memory for the structure AZ, which also contains a pointer to a second memory block.  When the call is made to free the memory pointed to by AZ, a permanent memory leak occurs because the second memory block for the embedded pointer cannot be freed.

...

typedef struct ptrblock

{

char *ptr;

} AZ;

...

AZ *p;

p = (AZ *)malloc(sizeof(*p));

p->ptr = malloc(10);

free(p);

...

Repair

This error frequently occurs when you free a memory block without freeing an enclosed memory block. You can fix this problem by making the appropriate call to free the enclosed memory before attempting to free the block in which is contained.

When attempting to fix this error, ensure that you free memory blocks in the appropriate order. If you revise the sample code as follows, an error still occurs because the blocks are freed in incorrect order.

...

free(p);

free(p->ptr);

...

This example shows the effect of freeing memory blocks in the wrong sequence: the second call to free may fail, because the first call to free could have set the related memory block to zero or deleted the contents of that memory block. This could result in a failure because the second call to free uses what has become an invalid value (p->ptr).


  Memory leaked due to reassignment

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when a dynamically allocated memory block cannot be freed due to a pointer assignment. This typically occurs when the related pointer is the last remaining pointer to the allocated block.

Sample Code

The following code shows an example of this error. In this case, the sample code creates a pointer (c) and allocates a block of memory for that pointer. When the pointer is reassigned to a stack-based memory block, the dynamically allocated block cannot be freed.

...

char *c, d[10];

c = (char *)malloc(10);

c = d;

...

Repair

This error frequently occurs when you do not free a previously allocated memory block before reassigning a pointer. The following code repairs the memory leak that results from the above sample:

...

c = (char *)malloc(10);

free(c);

c = d;

...


  Memory leaked leaving scope

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when a function allocates a memory block, then returns without deallocating that memory block or storing a pointer to that block in an external variable. This creates a condition where the memory block cannot be deallocated.

Sample Code

The following sample shows a function (getmem) that allocates a block of memory, but does not deallocate that memory before returning from the function. Because the allocated cannot be freed, a memory leak occurs.

...

void getmem()

{

char *d;

d = malloc(10);

return;

}

...

getmem();

...

Repair

You can resolve this error by ensuring that you free (deallocate) a memory block before you return from a routine. To fix the sample code you would need to add a call to free(d) before return.

Note that this error frequently occurs when revising existing code. For example, if some other error condition causes you to return from a routine before it has completed, the memory previously allocated for that function will not be freed, resulting in a memory leak.


  Reading overflows memory

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when you try to read from a section of memory that is not within the valid range for that block.

Sample Code

Problem 1

The following sample copies the string c into the array d. The error occurs when memcpy tries to read beyond the end of string c.

...

char *c = "TEST";

char d[20];

memcpy (d, c, sizeof (d));

...

Problem 2

A second but much more infrequent case arises because data structures (TEXTMETRIC, for example) can be compiled into different sizes (an effect known as “alignment” or “structure packing”), depending on which compiler and command-line options you use. Different compilers have different default behavior when it comes to packing.

For example, the Microsoft compiler aligns to 8-byte boundaries by default, whereas the Borland compiler defaults to 1-byte alignment. Checking for memory writes in known structures is based on a fixed size that is calculated in advance. If your program uses a different packing criteria than expected, an error is detected. If the actual structure size in the TEXTMETRIC example is 53 bytes, a program built with 8-byte packing treats the structure size as if it was 56 bytes.

...

TEXTMETRIC tm;

GetTextMetrics(hDC, &tm);

...

Repair

This error frequently results from simple errors in source code, such as using the wrong variable or an invalid sizeof operator.  The sample code shown for Problem 1, which reads past the end of a string, can be fixed by changing:

memcpy (d, c, sizeof (d));

to:

memcpy (d, c, strlen (c) + 1);

In the case of Problem 2, the solution is more complex. Most compilers provide pragmas that can be used within header files to ensure that important data structures are always packed in a consistent fashion. The Microsoft compiler does not use these directives for all structure definitions in the Windows headers.

If this error is reported on a Windows structure in your code, and you are certain that your code is correct, you may want to ensure that your code is built with packing. For Microsoft compiler users, this is done with the /Zpn command line switch or with #pragma pack(n); with Borland compilers, this is done with the -an command line switch or with #pragma option -an (where n is the byte alignment value).


  Reading uninitialized memory

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when you use an uninitialized variable or attempt to read from an uninitialized memory block.

Note that references to uninitialized memory may not result in an immediate error condition, but can lead to other errors as you continue to code.

Sample Code

Problem 1

The following sample contains an uninitialized variable (box.height):

...

struct square {

int width;

int height;

};

struct square box;

int area;

box.width = 5;

area = box.width*box.height;

printf("area = %d\n", area);

...

Problem 2

The following sample code assigns a value to  r using memory from an uninitialized call to  malloc. Because r is assigned an uninitialized value, subsequent use of that variable will result in an error.

...

char *s = (char *) malloc (5);

char r;

r = *s;

...

Repair

Typically, you can resolve these errors by ensuring that you initialize the affected variables. If this does not correct the problem, verify the correct initialization of any other variable used to assign a value to the first.


  Returning pointer to local variable

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error occurs when a function returns a pointer to a non-static local variable. In this case, the pointer is invalid because the stack frame for the routine is no longer available when the functions returns.

Sample Code

char *MakeFullName(char *FirstName)

{

char array[80];

  	strcpy(array, FirstName);

      strcat(array, "Smith");

// Return pointer to local variable

return array;

}

Repair

•	To resolve this error, try one of the following solutions:

•	Define the memory block as static, rather than non-static.

•	Dynamically allocate the memory block and use a pointer (rather than the stack) for the return value.

•	Change the local variable to a global variable.


  Writing overflows memory

 Description	 Sample Code	 Repair

Instrumentation with BoundsChecker, version 5.0, FinalCheck, required to find this error

Description

This error can occur when you attempt to write a string or other data that exceeds the valid range for the related block of memory.

Sample Code

Problem 1

The following sample tries to copy a string into array z. The error occurs because the string exceeds the defined array.

...

char z[10];

strcpy (z, "A simple test");

...

Problem 2

A second fairly common case arises when strings are not terminated properly. The following code copies a string using the strncpy routine, which leaves it non-terminated because the buffer is too short. When you attempt to print this message, an error results.

...

char b[8];

strncpy (b, "This is a test", sizeof (b));

printf("%s\n", b);

...

Problem 3

A third, but much more infrequent case arises because data structures (TEXTMETRIC, for example) can be compiled into different sizes (an effect known as “alignment” or “structure packing”), depending on which compiler and command-line options you use. Different compilers have different default behavior when it comes to packing.

For example, the Microsoft compiler aligns to 8-byte boundaries by default, whereas the Borland compiler defaults to 1-byte alignment. Checking for memory writes in known structures is based on a fixed size that is calculated in advance. If your program uses a different packing criteria than expected, there will be discrepancies and an error will be detected. Using the TEXTMETRIC example again, if the actual structure size is 53 bytes, a program built with 8-byte packing will treat the structure size as if it was 56 bytes.

...

TEXTMETRIC txtm;

memset (&txtm, 0, sizeof (txtm));

...

Repair

Typically, this error can be resolved by increasing the size of the destination object.  The sample code for Problem 1 can be corrected by increasing the size of the array, as follows:

...

char a[15];

strcpy (a, "A simple test");
...

In the case of Problem 3, the solution is more complex. Most compilers provide pragmas that can be used within header files to ensure that important data structures are always packed in a consistent fashion. The Microsoft compiler does not use these directives for all structure definitions in the Windows headers.

If this error is reported on a Windows structure in your code, and you are certain that your code is correct, you may want to ensure that your code is built with proper packing. For Microsoft compiler users, this is done with the /Zpn command line switch or with #pragma pack(n); with Borland compilers, this is done with the -an command line switch or with #pragma option -an (where n is the byte alignment value).


API Failure - Windows Function Failed
API failure: Windows function failed

 Description	 Sample Code	 Repair

Description

An API function returned a failure status.

Note that an API failure may not indicate an error in your program. Some calls to API functions are expected to fail, and the calling program deals with the failure appropriately. An API failure is only an error if your program does not provide for the failure condition.

C++ Sample Code

Often an API failure is expected. In the following example, the call to LoadBitmap fails if the resource does not exist:

HBITMAP hBitmap = LoadBitmap ( GetModuleHandle ( NULL ) ,

_T ( "HappyBitmap")

) ;

Pascal Sample Code

The following example shows a similar error in Pascal code:

Penguin := LoadBitmap (  GetModuleHandle(NIL), 'HappyHappy');

Probable Causes

•	Passing an argument that is inappropriate for the function

•	An invalid API call or sequence of API calls

•	Use of an API not supported on the operating system (Windows NT or Windows 95)

Repair

If an API fails and the return value is not checked, other sections of the program might not behave properly. Some suggested courses of action are:

•	Check the return code for more information as to why the API failed. For a complete description of the error codes, refer to the Win32 API Help File.

•	Place conditionals around the API so a failure is handled properly by your program. If you already have conditionals around the API, you may want to suppress the error.

•	Look at the return code to see the reason for the failure and take action based on this information.


API Failure - Windows Function Not Implemented
  API failure: Windows function not implemented

 Description	 Sample Code	 Repair

Description

An API function failed because it was not implemented by the operating system.

C++ Sample Code

The following Win32C call produces an error if used in Windows NT:

HeapValidate  ( GetProcessHeap  ( ) , 0 , NULL ) ;

Pascal Sample Code

The following example shows a similar error in Pascal code:

hMenu := LoadMenu( GetModuleHandle('bugbnchx.exe'), 'Hello');

Probable Causes

•	Using a Win32C call in Windows NT

•	Using a Win32NT call in Windows 95

Repair

If this error occurs in your program there are two possible courses of action. The first is to remove the offending API call(s) from your program. You can use Win32 Compliance checking to see what calls you are making that are specific to an operating system.

The second option is to test which operating system is running by using the API, GetVersion( ). If the correct operating system is not running, then you can circumvent the call(s).


  Dynamic memory overrun

 Description	 Sample Code	 Repair

Description

A routine is about to overrun the boundary of a dynamic data object.

C ++ Sample Code

The following code writes 12 bytes to a 10-byte array:

char*a = malloc (10);

memset (a, 0, 12);

Pascal Sample Code

The following example shows a similar error in Pascal code:

Overrun2 := StrAlloc (4);
FillChar {Overrun2, ‘0’, 6);

Probable Causes

•	 Passing a source string that is not NULL terminated

•	 Passing a source string too long for the destination

•	 Passing an incorrect length argument

Repair

The simplest repair is to allocate more memory for the dynamic data object. In the above C++ sample, changing malloc to allocate 12 bytes instead of 10 resolves the error.


  Freed handle is still locked

 Description	 Sample Code	 Repair

Description

You attempted to free a handle that was locked by a call to LocalLock or GlobalLock, and you have not called the appropriate Unlock function.

C++ Sample code

...

HANDLE hMem;

LPVOID lpMem;

hMem = GlobalAlloc (GHND, 0x100);

lpMem = GlobalLock(hMem);

GlobalFree (hMem);  //Error is

reported here

...

Pascal Sample Code

...

   Flip: HGLOBAL;

   Flap: PChar;

      Flip := GlobalAlloc(GHND, $100);

      Flap := GlobalLock ( Flip );

      GlobalFree ( Flip );

...

Probable Cause

•	Forgetting to unlock a handle when finished with it.

Repair

The repair for this error is to unlock all blocks of memory before freeing those blocks.

Note that when writing 16-bit Windows programs, many programmers lock their blocks in memory. In general, locked blocks should be unlocked before being freed. While unlocking is no longer required for 32-bit Windows programs, if your code locks memory blocks without the corresponding unlock, this condition is detected.

In all cases, calling the appropriate unlock function fixes this error.


  Handle is already unlocked

 Description	 Sample Code	 Repair

Description

You tried to unlock a handle that was not locked. You used either LocalUnlock or GlobalUnlock twice in succession on the same handle.

C++ Sample Code

The following sample attempts to unlock a handle that is already unlocked:

...

HANDLE a = GlobalAlloc(GHND, 0x100);

GlobalLock(a);

GlobalUnlock(hGlobalMemory);

GlobalUnlock(hGlobalMemory);

GlobalFree(a);

...

Pascal Sample Code

The following example shows a similar error in Pascal code:

...

   Flip: HGLOBAL;

begin

   Flip := GlobalAlloc(GHND, $100);

   GlobalUnlock( Flip );

   GlobalFree( Flip );

end;

Repair

While there are no adverse effects on your program from unlocking a block twice, this condition indicates the potential misuse of a handle. This error might be pointing out that the program was using a handle that it thought was locked but in actuality was not. A careful check of the program should be done to make sure that this is not the case. The fix to the above sample code is to remove one of the references to GlobalUnlock.


  Interface leak

 Description 	 Sample Code	     Repair

Description

Calling CoCreateInstance without releasing the interface pointer generates an interface leak.

Sample Code

LPUNKNOWN lpUnk ;

HRESULT hr = CoCreateInstance ( clsidIFace , NULL , CLSCTX_INPROC_SERVER , IID_IUnknown , (LPVOID*)&lpUnk ) ;

if ( NOERROR ( hr ) )

return ;

Repair

Call the Release method on the interface.


  Interface method failure

 Description	 Sample Code	 Repair

Description

An OLE interface method returned a failure status.

Note that an interface method failure may not indicate an error in your program. Some calls to OLE interface methods are expected to fail, and the calling program deals with the failure appropriately. An interface method failure is only an error if your program does not provide for the failure condition.

Sample Code

IUnknown::QueryInterface must take a valid reference to an IID.

...

LPVIEWOBJECT lpVwObj ;

HRESULT hrExpectFail = lpUnk->QueryInterface ( (REFIID)NULL, (LPVOID*)&lpVwObj) ;

...

Probable Causes

•	Passing an argument that is inappropriate for the method

•	An invalid sequence of OLE interface calls or an OLE interface call that is invalid at this time

•	Incomplete understanding of the OLE Interface call

Repair

If an OLE interface fails and the return value is not checked, other sections of the program might not behave properly. Some suggested courses of action are:

•	Check the return code for more information as to why the OLE interface failed. For a complete description of the error codes, refer to the OLE interface documentation.

•	Place conditionals around the OLE interface so a failure is handled properly by your program. If you already have conditionals around the OLE interface, you may want to suppress the error.

•	Look at the return code to see the reason for the failure and take action based on this information.


  Invalid argument

 Description	 Sample Code	 Repair

Description

You have passed an invalid memory address as a pointer to a Windows API function.

C++ Sample Code

...

LoadBitmap (hinst, 0x410);

...

Pascal Sample Code

...

   color := GetTextColor ( HDC($abcd));

...

Visual Basic Sample Code

The following code results in an error because lpBuffer is not initialized. (The error could be corrected by the insertion of the line: lpBuffer = Space$(128) )

Text1 = "working"
GetSystemDirectory lpBuffer, Len(lpBuffer)
Text1 = UCase(Left(lpBuffer, InStr(lpBuffer, Chr(0)) - 1)) & "\" & Combo1
Text1.SetFocus

Repair

Generally, this error only causes an API failure. However, if the program depends on this API call succeeding, the program will not function properly. Make sure that pointers passed to API Calls have been initialized properly. For more information on the API and its parameters, refer to the Win32 API online Help.


Invalid Argument - At Least One Format Specifier is Illegal
  Invalid argument: At least one format specifier is illegal

 Description	 Sample Code	 Repair

Description

The members of the printf family of functions that are supplied in the Win32 API (wsprintf and wvsprintf) are subsets of the sprintf and vsprintf functions in the standard C/C++ runtime library. Some format specifiers, especially those related to floating-point numbers, are not supported in the Win32 variants.

Sample Code

Because wsprintf does not support the %f format specifier, the following line of code produces the output "Pi = ", which is probably not what you wanted:

wsprintf(szBuffer, "Pi = %f", 3.141592);

Repair

When using wsprintf/wvsprintf, check the Win32 API documentation to ensure that the formats you want to use are supported.


Invalid Argument - Bad Destination Pointer
  Invalid argument: Bad destination pointer

 Description	 Sample Code	 Repair

Description

A C-library function was called with a bad destination pointer.

C++ Sample Code

...

char buffer[20];

strcpy (NULL, buffer);

...

Pascal Sample Code

...

     StrCopy ( '', buffer );

...

Repair

An error like this should be fixed immediately. In the above case, writing to NULL causes a general protection fault. The fix would be to replace NULL with a valid destination buffer (dynamic or static). A probable cause of this error is passing an uninitialized pointer as the destination pointer.


Invalid Argument - Bad Handle
  Invalid argument: Bad handle

  Description	  Sample Code	Repair

Description

A call was made to free or reallocate a memory address that did not point to a legitimate allocated memory block.

C++ Sample code

...

HANDLE ptr = 0x10;

LocalFree (ptr);

...

Pascal Sample Code

...

      MemoryBlock := AllocMem(50);

      FreeMem(MemoryBlock,50);

      FreeMem(MemoryBlock,50);

...

Repair

A call to a free or realloc routine with a bad address often causes heap corruption. Because these routines assume this is a good block, they manipulate internal structures which might cause overwriting of valid data and almost certainly corrupt the free list in the heap.

A bad address can be generated from calling one of these routines with a pointer that was never allocated or with a pointer that was already freed. To fix the sample code above, a call to LocalAlloc ( ) should be made to provide ptr with a valid address.


Invalid Argument - Bad Source Pointer
  Invalid argument: Bad source pointer

 Description	 Sample Code	 Repair

Description

You passed an invalid source address of a string or block of memory to a library function. The message also indicates the name of the argument and its value:

Bad source pointer.  Pointer = nnn

•	Pointer is the pointer name

•	nnn is the value of the pointer

C++ Sample Code

...

char buffer[20];

strcpy (buffer, NULL); //Reports bad

 source pointer

...

Pascal Sample Code

...

var

  	Flip : array [0..12] of Char;

begin

 	StrLCopy ( Flip, NIL, 4 );

end;

...

Repair

This error is most likely caused by the use of an uninitialized pointer. Having this error in a program can lead to serious program flaws and should be fixed immediately. Fixing the sample code above is as simple as passing a valid string as the source pointer.

...

char buffer[20];

strcpy ( buffer, "This is a valid string");


Invalid Argument - Conflicting Combination of Flags
  Invalid argument: Conflicting combination of flags

 Description	 Sample Code	 Repair

Description

The function passed an argument that contained two or more bit flags that cannot be set together. The function expects that certain combinations of bit flags are mutually exclusive.

Some Windows API functions (OLE INTERFACE MEHODS) take arguments that contain bit flags packed into a WORD or DWORD. In many cases, certain combinations of flags are conflicting, and therefore invalid. Checking occurs for invalid combinations of bits in all bit flag arguments.

The name of the flag argument and the invalid value are indicated in the message:

FunctionName param # is invalid - PARAMNAME:paramvalue

C++ Sample Code

...

SetPriorityClass(GetCurrentProcess(),

IDLE_PRIORITY_CLASS |

NORMAL_PRIORITY_CLASS);

...

Pascal Sample Code

...

      GetStringTypeEx ( GetUserDefaultLCID(),

CT_CTYPE1 OR CT_CTYPE2,

szSource,

-1,

szDest        );

...

Repair

Normally, the invalid bits are ignored or cause the API function to fail. For more information about the API and which flags can and should be used together, refer to the Win32 API online Help.


Invalid Argument - Format String is Not Followed by Valid Arguments
  Invalid argument: Format string is not followed by valid arguments

 Description	 Sample Code	 Repair

Description

The format string for this v..printf- or wv..printf-style function is followed by an invalid argument pointer.

Sample Code

If the variable pArgs is not properly initialized, vsprintf fails.

va_list pArgs;

vsprintf(szBuffer, "Error on line %d: %s", pArgs);

Repair

Calls made to these functions must be followed by valid arguments. This error can occur when one of these functions is called with an uninitialized variable. For more information about these functions, refer to the Win32 API online Help.


Invalid Argument - Invalid Pointer to Format String
  Invalid argument: Invalid pointer to format string

 Description	 Sample Code	 Repair

Description

The format string to this printf-style function was not a valid pointer.

Sample Code

In the following example, the programmer forgot to reset the format variable:

char *format = NULL;

.

.

.

printf(format,m);

Repair

Allowing the call to continue could cause a serious error. The most  probable cause for this error is an uninitialized variable, as in the sample code above. To fix the sample code, a call to an allocation routine such as malloc should be made to assign format to a legal address.


Invalid Argument - Not Enough Arguments for this Format String
  Invalid argument: Not enough arguments for this format string

 Description	 Sample Code	 Repair

Description

The format string for this printf-style function contained more specifiers than there were arguments passed.

Sample Code

In this example, the format string contains three format specifiers, but is followed by only two data arguments:

sprintf(szBuffer, "Error %d in line %d:

%s", errorNum, lineNum);

Repair

Examine the code carefully to determine if you have one too many specifiers or not enough arguments. In either case, a fix should be made. In the above case, the "%s" should be removed or a string variable added as the last argument.


Invalid Argument - Out of Range
  Invalid argument: Out of range

 Description	 Sample Code	 Repair

Description

The function expects that this argument is confined to a specific range of values. The argument passed was outside of this range.

C++ Sample Code

...

GetStdHandle(42);

...

Pascal Sample Code

...

Beep ( 36, 10 );

...

Repair

Some arguments of Windows API functions must fall in a specific range. Each argument is checked and this error is reported if the value you passed is outside the allowable range. Refer to the Win32 API online Help to find the acceptable ranges and then add the appropriate code to your source files.


Invalid Argument - Structure Size Field is Not Initialized
  Invalid argument: Structure size field is not initialized

 Description	 Sample Code	 Repair

Description

The size field for a Windows API structure was not properly initialized.

C++ Sample Code

...

OSVERSIONINFO os;

memset(&os, 0, sizeof(os));

GetVersionEx(&os);

...

Pascal Sample Code

...

      FillChar (stOSVI, Sizeof(stOSVI), 0 );

      GetVersionEx(stOSVI);

...

Repair

For APIs that require the structure size field to be initialized, a simple line of code fixes the problem. In the above case, the following line fixes the problem:

os.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );

Refer to the Win32 API online Help for more information.


Invalid Argument - Too Many Arguments for this Format String
  Invalid argument: Too many arguments for this format string

 Description	 Sample Code	 Repair

Description

The format string for this printf-style function contained fewer format specifiers than there were value arguments passed.

Sample Code

sprintf(szBuffer,"Error %d in line %d",

errorNum, lineNum, pszErrorText);

Repair

The extraneous argument is ignored. However, the code should be carefully checked to ensure that information is not missing from the statement.


Invalid Argument - Undefined or Illegal Flags
  Invalid argument: Undefined or illegal flags

 Description	 Sample Code	 Repair

Description

The function expects that only certain bit flags will be turned on when called. The argument passed contained bits that are undefined or not allowed for this function.

C++ Sample Code

...

hGlobalMemory = GlobalAlloc(0xFFFFFFFF, 0x100);

...

Pascal Sample Code

...

      TestMenu := CreateMenu ( );

      AppendMenu ( TestMenu,

                   $0008000,

                   $100,

                   '&New Item' );

      DestroyMenu ( TestMenu );

...

Repair

Some Windows API functions take arguments in the form of bit flags packed into a WORD or DWORD. To find the valid flags for the API, refer to the Win32 API online Help.


  Invalid interface method argument

 Description	 Sample Code	 Repair

Description

You have passed an invalid memory address as a pointer to a Windows OLE interface method.

Sample Code

Passing an uninitialized pointer to IUnknown::QueryInterface as a REFIID causes problems.

...

LPDATAOBJECT lpDataObj ;

HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IDataObject ,

(LPVOID*)&lpDataObj ) ;

FORMATETC* pFormatEtc = (FORMATETC*)0x01;

lpDataObj->QueryGetData( pFormatEtc ) ;

...

Repair

Generally, this error only causes an OLE interface failure. However, if the program depends on this OLE interface call succeeding, the program will not function properly. Make sure that pointers passed to OLE interface calls have been initialized properly. For more information on the OLE interface and its parameters, refer to the OLE interface documentation.


Invalid Interface Method Argument - Conflicting Combination of Flags
  Invalid interface method argument: Conflicting combination of flags

 Description	 Sample Code	  Repair

Description

The OLE interface method expects that certain combinations of bit flags are mutually exclusive. The argument passed contained two or more bit flags that cannot be set together.

Some OLE interface methods take arguments that contain bit flags packed into a WORD or DWORD. In many cases, certain combinations of flags are conflicting, and therefore invalid. Checking occurs for invalid combinations of bits in all bit flag arguments.

The name of the flag argument and the invalid value are indicated in the message:

FunctionName param # is invalid - PARAMNAME:paramvalue

Sample Code

IViewObject::SetAdvise can take only one of the following for its first parameter:  DVASPECT_CONTENT, DVASPECT_THUMBNAIL, DVASPECT_ICON, DVASPECT_DOCPRINT

...

LPVIEWOBJECT lpVwObj ;

HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;

if ( S_OK != hrExpectOk )

{

return ;

}

lpVwObj->SetAdvise ( DVASPECT_CONTENT | DVASPECT_THUMBNAIL ,

ADVF_ONLYONCE	,

NULL	) ;

...

Repair

Normally, the invalid bits are either ignored or cause the OLE interface method to fail. For more information about the OLE interface and which flags can and should be used together, refer to the OLE interface documentation.


Invalid Interface Method Argument - Out of Range
  Invalid interface method argument: Out of range

 Description	 Sample Code	 Repair

Description

The OLE interface method expects that this argument is confined to a specific range of values. The argument passed was outside of this range.

Sample Code

Reserved parameters of some interface methods must be zero or NULL.

...

LPVIEWOBJECT lpVwObj ;

HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;

if ( S_OK != hrExpectOk )

{

return ;

}

HDC dcRender = CreateDC ( _T ( "DISPLAY" ), NULL , NULL , NULL ) ;

RECTL rectBounds;

rectBounds.left   = 100 ;

rectBounds.right  = 100 ;

rectBounds.top    = 100 ;

rectBounds.bottom = 100 ;

lpVwObj->Draw ( DVASPECT_CONTENT ,

0	,

(LPVOID) 1  ,

NULL	,

NULL	,

dcRender	,

&rectBounds	,

NULL	,

NULL	,

0	) ;

...

Repair

Some arguments of OLE interface methods must fall in a specific range. Each argument is checked and this error is reported if the value you passed is outside the allowable range. Refer to the Win32 API online Help to find the acceptable ranges and then add the appropriate code to your source files.


Invalid Interface Method Argument - Structure Size Field is not Initialized
  Invalid interface method argument: Structure size field is not initialized

 Description	 Sample Code	 Repair

Description

The size field for an OLE interface structure was not properly initialized.

Sample Code

The tdSize field of the target device should be initialized.

...

LPVIEWOBJECT lpVwObj ;

HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;

if ( S_OK != hrExpectOk )

{

return ;

}

HDC dcRender = CreateDC ( _T ( "DISPLAY" ), NULL , NULL , NULL ) ;

RECTL rectBounds;

rectBounds.left   = 100 ;

rectBounds.right  = 100 ;

rectBounds.top    = 100 ;

rectBounds.bottom = 100 ;

DVTARGETDEVICE dvTarget ;

lpVwObj->Draw ( DVASPECT_CONTENT ,

0                ,

NULL             ,

&dvTarget        ,

NULL             ,

dcRender         ,

&rectBounds      ,

NULL             ,

NULL             ,

0  ) ;

...

Repair

For those OLE interfaces that require the size field of a structure to be initialized, a single line of code fixes the problem. The following line fixes the problem in the sample code:

...

DVTARGETDEVICE dvTarget ;

dvTarget.tdSize = sizeof ( dvTarget ) ;

lpVwObj->Draw ( DVASPECT_CONTENT ,

0	,  /* View index                 */

NULL	,  /* Must be NULL               */

&dvTarget	,  /* Target Device description  */

NULL	,  /* Target Device info context */

dcRender	,  /* Device context to draw on  */

&rectBounds	,  /* Bounding rectangle         */

NULL	,  /* Window bounding rect       */

NULL	,  /* Call-back routine          */

0	   /* Continue call-back param   */ ) ;

...


Invalid Interface Method Argument - Undefined or Illegal Flags
  Invalid interface method argument: Undefined or illegal flags

 Description	 Sample Code	 Repair

Description

The method expects that only certain bit flags will be turned on when called. The argument passed contained bits that are undefined or not allowed for this method.

Sample Code

IViewObject::SetAdvise can only take the ADVF_ONLYONCE and ADVF_PRIMEFIRST flags or a combination of the two for its second parameter.

...

LPVIEWOBJECT lpVwObj ;

HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;

if ( S_OK != hrExpectOk )

{

return ;

}

lpVwObj->SetAdvise ( DVASPECT_CONTENT ,

ADVF_NODATA	,

NULL	) ;

...

Repair

Some OLE interface methods take arguments in the form of bit flags packed into a WORD or DWORD. To find the valid flags for the OLE interface, consult the OLE interface documentation.


  Memory allocation conflict

 Description	 Sample Code	 Repair

Description

A memory block was allocated with new (malloc) and freed with free (delete).

The two possibilities are distinguished as follows:

badfree	Memory was allocated with new or new [] and an attempt was made to free it with free.
baddelete	Memory was allocated with malloc and an attempt was made to free it with delete or delete[].
Some compilers do allow this practice, but it is not good programming and could lead to a portability problem.

Sample Code

Problem 1

The following code shows a typical example of allocating a block of memory with new and then freeing it with free instead of delete.

...

char *a;

a = new char;

free(a);

return 0;

...

Problem 2

The following code shows another example of this type of error: allocating a block of memory with malloc and then freeing it with delete.

...

char *a;

a = (char *) malloc(1);

delete a;

return 0;

...

Repair

To repair this type of error, verify that all program memory allocations are freed with the corresponding deallocation method.


  Memory leak

 Description	 Sample Code	 Repair

Description

A block of memory was allocated and never freed.

Any program that uses dynamic allocation of memory is prone to leave some memory allocated when the program finishes.

Note: If you are not seeing source code for the leak, then it is likely that the allocating module does not have debug information. This occurs mostly with third party packages or system code. However, you are provided with the address which can be used to determine the source line where the memory was allocated.

C++ Sample Code

The following code leaks memory by allocating it in a function and exiting the function before freeing the memory:

function_test(mem_var)

{

int *intptr;

intptr = (int *) malloc (1000

*sizeof (int));

}

Pascal Sample Code

The following shows a similar error in Pascal code:

procedure AllocMem_Leak;

var

  testPointer: Pointer;

begin

  testPointer := AllocMem ( 25 );

end;

Repair

The recommended action is to free all memory the program allocates. The source pane displays the line of code where the memory was allocated. You should then determine where the memory should be freed and free it. Memory leaks lead to bad performance and eventual program crashes. To correct the sample code, make a call to free.

free ( intptr );


  Pointer references unlocked memory block

 Description	 Sample Code	 Repair

Description

In Windows you can allocate memory as moveable. When you do this, you must lock the memory before you can use it.

C++ Sample Code

...

HANDLE hMem;

LPVOID lpPtr;

hMem = GlobalAlloc(GHND, 0x100);   //Allocate moveable memory

lpPtr = GlobalLock(hMem);          //Get pointer to memory

GlobalUnlock(hMem);                //Unlock pointer

memset(lpPtr,0,0x100);             //Use pointer and BC complains

GlobalFree(hMem);

...

Pascal Sample Code

procedure Ptr_Refs_Unlocked_Block;

var

   Flip: HGLOBAL;

   Flap: PChar;

begin

   try

      Flip := GlobalAlloc ( GHND, $100 );

      Flap := GlobalLock ( Flip );

      GlobalUnlock ( Flip );

      StrCopy ( Flap, 'Block is unlocked');

      GlobalFree ( Flip );

   except

   end;

end;

Repair

To repair the error, make sure the memory handle (hMem) is locked when you try to use a pointer to the block.


  Program fault

Description

A serious error, which has caused your program to shut down, has occurred. Because of the many possible causes for this error, there is no Sample Code or Repair.


  Questionable use of thread

 Description	 Sample Code	 Repair

Description

A thread, which makes calls to one or more run-time library functions, was created using CreateThread. A thread that uses functions from the C run-time libraries should use the _beginthread and _endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called.

Note: If the run-time library is statically linked and the module lacks debug info, it may not be possible for the call to _beginthread to be detected and this error is reported. In this situation, the error can be safely suppressed.

Sample Code

...

DWORD WINAPI aThread(void *arg)

{

    char *a = malloc (10);

    free (a);

    ExitThread(0);

}

void main()

{

    int i;

    DWORD id;

    HANDLE hThread2[NUM_THREAD];

    for (i = 0; i < NUM_THREAD; i++)

    {

        hThread2[i] = CreateThread(NULL, 0, aThread, NULL, 0, &id);

    }

    WaitForMultipleObjects(NUM_THREAD, hThread2, TRUE, INFINITE);

    for (i = 0; i < NUM_THREAD; i++)

    {

        CloseHandle(hThread2[i]);

    }

}

...

Repair

Use the C run-time functions _beginthread and _endthread to create and destroy threads, which use functions from the C run-time libraries.


  Resource leak

 Description	 Sample Code	 Repair

Description

A system resource (HBRUSH, DLL, file etc.) was created or opened and never freed or closed.

When your program terminates, checking occurs to ensure you have freed all allocated blocks of memory and resources, and all blocks and resources still allocated, along with their size and location, are automatically listed.

Note: If you are not seeing source code for the leak then it is likely that the allocating module does not have debug information. This occurs mostly with third party packages or system code. However, you are provided with the address which can be used to determine the source line where the memory was allocated.

C++ Sample Code

...

hResource = LoadResource (hInstance,

FindResource (hInstance,

"TEXT", RT_STRING));

/* without a later

FreeResource statement;  */

...

Pascal Sample Code

The following shows a similar error in Pascal code.

procedure BitmapLeak;

var

   hBitmap: THandle;

begin

   hBitmap := CreateBitmap(80,80,1,8,NIL);

end;

Repair

Under Windows 95 and Windows NT, resource leaks are a serious problem because resources are not always freed when an application terminates. Frequently, the only way to repair this problem is to exit from and restart Windows. You can also fix some resource leaks with the same techniques used for memory leaks.


  Stack memory overrun

 Description	 Sample Code	 Repair

Description

A library routine was about to write past the end of a local variable.

C++ Sample Code

The following code copies too many data items to a local array:

void function_1 ( void )

{

char array[10];

strcpy ( array, "This will overwrite");

}

Pascal Sample Code

The following shows a similar error in Pascal code:

procedure StackOverrun;

var

  ToOverrun : array[0..5] of char;

begin

      StrCopy ( ToOverrun, 'Overrun');

end;

Repair

An overrun like this corrupts data on the stack, including return addresses, thus causing odd program behavior. Possible causes of this error include: passing a string that is not NULL terminated or passing a source string too long for the destination. When repairing this problem, remember that literal strings are followed by an implied NULL character.

If this error is reported on a Windows structure in your code, and you are certain that your code is correct, you may want to ensure that your code is built with proper packing. For Microsoft compiler users, this is done with the /Zpn command line switch or with #pragma pack(n); with Borland compilers, this is done with the -an command line switch or with #pragma option -an (where n is the byte alignment value).

The fix to the C++ sample code is:

void function_1(void )

{

char array[256];

strcpy ( array, "This will overwrite ");

}


  Static memory overrun

 Description	 Sample Code	 Repair

Description

A library routine was about to write past the end of a static variable (either a global variable or a static variable inside of a function).

Sample Code

The following code copies one too many data items to a local static array:

void function_1 ( void )

{

   static char array[10];

   strcpy ( array, "This will overwrite ");

}

Repair

With this error, the program's heap could be corrupted. To fix this specific problem, make sure the source buffer is NULL terminated and is not passing more data then the destination buffer can hold. To fix the sample code, increase the size of array to fit the source string.


  Unallocated pointer

 Description	 Sample Code	 Repair

Description

You allocated a pointer, then continued using that pointer after it was freed.

C++ Sample Code

A probable cause of this error is using an unallocated pointer in a memcpy or strcpy command.

The following code uses a pointer to refer to memory that has not been allocated:

...

char *a = malloc(10);

memset(a-1, 0, 5);

...

Pascal Sample Code

The following shows a similar error in Pascal code:

...

GetMem ( String1, 10 );

FreeMem ( String1 );

StrCopy ( Destination, String1 );

...

Repair

Continuing will probably cause a general protection fault. Terminate the program and fix the error.