Building and Debugging Libraries and ActiveX Controls
After creating a project, you're ready to build and debug it.
Building the Project
Before building, you need to establish the project settings. Some of the settings you make depend on whether you want to create a debug or release version of the control or library. As a rule, you create debug versions of the program until you're satisfied that it's working correctly, and then you create a release version.
To specify a debug or release version
- From the Build menu, choose Set Default Configuration.
- Choose whether you're creating a debug or release version of the control.
- Choose OK.
To establish project settings
- From the Build menu, choose Settings.
- Under Settings For, choose whether you're creating a debug or release version of the program.
- Click the C/C++ tab and then make these settings:
- In the Category list, choose Code Generation.
- In the Calling Convention list, choose _fastcall.
- In the Use run-time library list, choose Multithreaded DLL.
- Choose the Link tab and then in the Object/Library Modules text box, add one of the following libraries:
- If you're building an .ocx, add
OCXAPI.LIB
from the Visual FoxPro API directory. - If you're building an .fll, add
WINAPIMS.LIB
from the Visual FoxPro API directory.
- If you're building an .ocx, add
- Unmark Ignore all default libraries.
- Choose OK.
To make sure the compiler can find the necessary files
- From the Tools menu, choose Options.
- Click the Directories tab.
- In the Show directories for list, choose Include files.
- In the Directories toolbar, click the Add button.
- Add the directory with Pro_ext.h.
- In the Show directories for list, choose Library files.
- In the Directories toolbar, click the Add button.
- Add the directory with Ocxapi.lib from the Visual FoxPro API directory (when creating a control) or add the Winapims.lib from the Visual FoxPro API directory (when creating an FLL)
- In the Options dialog box, choose OK.
After you've specified the settings, you can compile and link your program.
To compile and link an .ocx file
- From the Build menu, choose Buildprojname**.ocx**.
When you compile and link the .ocx file, Visual C++ automatically registers the control on the computer on which it was built. If for any reason you must register the control manually, you can do so using the following procedure.
To register the ActiveX control
From the Tools menu in the Microsoft Development Environment, choose Register Control.
-or-
Declare and call DLLRegisterServer( ) from your program.
Debugging an ActiveX Control or FLL Library
Debugging the control or library in the context of a full Visual FoxPro application is more difficult than debugging it separately from the application. It's a good idea to create a simple test program to test the operation of your control or library.
Debugging with the Microsoft Development Environment
Microsoft Visual C++ version 4.0 and higher offers an integrated debugging environment that makes it easy to set break points and to step through your code. You can even run Visual FoxPro from Visual C++.
To start debugging with Microsoft Visual C++
From the Build menu, choose Settings.
In the Project Settings dialog box, click the Debug tab.
In the Executable for debug session text box, type the path followed by Vfp7.exe.
For example, type: C:\Program Files\Microsoft Visual FoxPro 7.0\Vfp7f.exe.
Choose OK.
Set a break point in your library.
From the Build menu, choose Debug. Then, from the submenu choose Go.
When Visual Studio displays a message that says "Vfp7.exe doesn't contain debugging information," choose Yes to continue.
For more information about debugging in Visual C++, see the Visual C++ documentation set.
Debugging with Other Debuggers
You should be able to debug a control or library with any debugger that correctly handles an INT 3 (_BreakPoint( )) embedded in your program. You can use any debugger for symbolic debugging as long as it can do all of the following:
- Make a symbol table from a map file.
- Load the symbol table independent of the program.
- Relocate the symbols to a new address.
To debug a library
Add a _BreakPoint( ) call to the routine at the point where debugging will begin.
Build the control or library.
Invoke your debugger.
If your debugger supports symbols, load the symbol table for your library.
Start Visual FoxPro.
Call your library routine from Visual FoxPro.
When the breakpoint is reached, make adjustments to the symbol base to align your symbols with the actual location where the library was loaded.
Increment the instruction pointer (IP) register by 1 to skip over the INT 3 instruction.
Continue debugging as with a normal program.
Note Always remove any breakpoints specified in your debugger before you release your product.
See Also
Managing Memory | Access to Visual FoxPro Variables and Fields | Accessing the Visual FoxPro API | Extending Visual FoxPro with External Libraries | Return of a Value to Visual FoxPro