## BUG: Enabling Callback Functions in SQLTEST3.EXE

Q114095

The information in this article applies to:

- Microsoft SQL Server Programmer's Toolkit, version 4.2

BUG# 9984 (4.2)

## SYMPTOMS

The error and message handlers in the sample Windows-based DB-Library (DB-Lib) program SQLTEST3.EXE (shipped with both DB-Lib version 4.21.00, date: 1/26/94, size: 18432 and DB-Lib version 4.20.50, date: 8/24/93, size: 18432 in the \sql\dblib\samples directory ) do not work.
If the program SQLTEST3.EXE is run in the shipped version, there will be no pop-up window showing the messages from either SQL server or DB library.
For example:
If a valid server name is given, it connects without displaying the messages about changing database context. If an invalid server name is given, it simply waits for a time-out without reporting any errors.

## CAUSE

The Windows operating system requires error and message handling for DB- Library to be installed differently than MS-DOS does. The error and message handlers are callback functions, and Windows dynamic-link libraries (DLLs) can move around in memory between calls to a DLL. Therefore, you must install the error handler and message handler as exported callback functions.
When the Windows operating system executes a callback function, the data segment register is not set to the application's data segment; even though the error handler is part of the application. Making the error handler and message handler functions into procedure instances and exporting them in the .DEF file causes the Windows operating system to set up the data segment register correctly so that your handlers can access the application's data. When compiling with the Microsoft C/C++ compiler version 7.0 or later, declare the error and message handlers using __export or use the /Gw option to load the correct DS for all functions.
For more details, see "Programmer's Reference for C" in Microsoft SQL Server for Windows NT Programmers Toolkit.

## WORKAROUND

The source code is correct. To install the error and message handlers correctly, just recompile it using the /Gw switch in C7, or if using VC++, change the compiler option of "Windows Prolog/Epilog" to be "Real Mode __far Functions," or modify the sqltest3.c code and declare the error and message handler functions as " export."

## STATUS

Microsoft has confirmed this to be a problem in SQL Server version 4.2 for OS/2 and Microsoft SQL Server version 4.2. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Additional query words: errorhandler messagehandler dblib Windows NT

Keywords : kbprogramming
Issue type :
Technology : kbSQLServSearch kbAudDeveloper kbSQLServPTK420

Last Reviewed: March 20, 1999 © 2001 Microsoft Corporation. All rights reserved. Terms of Use.