Additional Porting Considerations

DB Library for C

DB Library for C

Additional Porting Considerations

If you port a Windows-based application to the Microsoft® Windows NT® 4.0, Microsoft Windows® 95, or Windows 98 operating system and do not need to maintain compatibility with Windows, you can change your DB-Library code to remove redundant or unnecessary Windows functions.

Redundant Windows-specific DB-Library Functions

The dbwinexit function is Windows-specific and unnecessary in DB-Library for the Microsoft Win32® API.

Error/Message Handler Registration

The following changes apply to the registration of error and message handlers for the Win32 API:

  • No need to export callback functions.

    You don't need to export the DB-Library error and message handler callback functions in a .def file.

  • No need to call MakeProcInstance.

    You don't need to call MakeProcInstance to obtain a pointer to pass to the dberrhandle and dbmsghandle functions. Simply call dberrhandle and dbmsghandle, passing the function address. The following examples show the differences in calling the dberrhandle and dbmsghandle functions in Windows and in the Win32 API.

    For Windows:

    // Define variables 
    static FARPROC lpdbMsgHandler;
    static FARPROC lpdbErrHandler;
    
    // Get Procedure Instances
    lpdbMsgHandler = MakeProcInstance((FARPROC)dbMsgHandler, hInst);
    lpdbErrHandler = MakeProcInstance((FARPROC)dbErrHandler, hInst);
    
    // Install the instances into dblib 
    dbmsghandle(lpdbMessageHandler);
    dberrhandle(lpdbErrorHandler);
    

    For the Win32 API:

    // Install the instances into dblib 
    dbmsghandle(dbMsgHandler);
    dberrhandle(dbErrHandler);
    
Preemptive Multitasking (Win32) vs. Cooperative Multitasking (Windows)

To support asynchronous processing in the cooperative multitasking environment in Windows, each application must behave well and yield to the CPU at regular intervals. Therefore, when you process Microsoft SQL Server™ queries in Windows, you need to use Windows timers or the PeekMessage function in combination with the DB-Library function calls for asynchronous processing (dbsqlsend, dbdataready, and dbsqlok).

Support for preemptive multitasking in the Win32 API simplifies the implementation of asynchronous query processing. The preemptive multitasking nature of the Windows NT, Windows 95 and Windows 98 operating systems ensures that other processes always obtain CPU cycles regardless of any processing that another application is doing. Within a single process, asynchronous processing can be implemented using Win32 threads or by using the DB-Library functions that support asynchronous processing in conjunction with the PostMessage Windows function. For more information about asynchronous processing, see Taking Advantage of Win32 API Features in DB-Library Applications.