2 — Notes on Compiling and Linking


[Previous] [Next] [Contents] [Index]


This chapter provides information on compiling and linking PC-DCE™ programs. It contains the following sections:

2.1 Linking and Compiling PC-DCE Applications
2.2 Exception Handling
2.3 Using OLE 2.0 with PC-DCE
2.4 Generating Stubs from the IDL Command Line
2.5 Using the Microsoft IDE Interface

2.1 Linking and Compiling PC-DCE Applications

When you compile your PC-DCE programs, be sure to use the following compile switches:

-DWIN32 

-D_MT 

-D_DLL

-DWIN32_LEAN_AND_MEAN

The DCE API is exported via dce32.dll, so you must link your applications with dce32.lib.

If you do not want to link with the DLL version of the C runtime library, be careful when freeing memory returned by DCE API calls and RPCs. Use rpc_sm_client_free() to free this memory.

2.1.1 Using Non-Microsoft Compilers

Special instructions are available if you are using the OMF-compliant link library (dce32_omf.lib) supplied in this release to build PC-DCE applications with the Borland C compiler. Although not yet exhaustively tested in other non-MS environments, this library should also support the Symantec build environment.

Visit our Technical Support web page for PC-DCE at http://support.entegrity.com for more detailed instructions on using this library.

2.2 Exception Handling

PC-DCE provides support for exception handling that conforms to OSF DCE threads specification.

NOTE: PC-DCE exception handling is not the same as exception handling provided by Visual C++ and the native WIN32 support for structured exception handling. For a discussion of how to use DCE exception handling, refer to the OSF DCE Application Development Guide.

2.2.1 Global Unwinding

The exception handler provided by the C++ language provides global unwinding. In global unwinding, when an exception occurs, the exception handler calls the destructors for all objects on the stack between where the exception is raised and where it is caught. If you are accustomed to C++ exception handling, you should be aware that DCE exceptions do not provide a similar feature.

2.2.2 DCE Exception Handler Definitions for C++

C++ and DCE both define certain keywords, such as TRY, for exception handling. To avoid conflict in PC-DCE programs written in C++, Entegrity® has renamed the DCE macros using the prefix DCE_ as shown in Table 2-1.

Table 2-1: DCE Exception Handler Macro Redefinitions

DCE Default Name PC-DCE Name
RAISE

DCE_RAISE

TRY

DCE_TRY

CATCH

DCE_CATCH

CATCH_ALL

DCE_CATCH_ALL

RERAISE

DCE_RERAISE

FINALLY

DCE_FINALLY

ENDTRY

DCE_ENDTRY

In C programs, PC-DCE (in exc_handling.h) automatically redefines all instances of the DCE default names to the PC-DCE macro names. Programs written using the default names will use the DCE exception handler.

In C++, you must define the preprocessor directive STANDARD_DCE_EXCEPTIONS in order to redefine the DCE default names to the PC-DCE names. If STANDARD_DCE_EXCEPTIONS is not defined, you must use the PC-DCE names to invoke the DCE exception handler.

Be aware that the DCE and C++ exception handlers are not compatible.

2.2.3 Runtime Library Requirement

The PC-DCE exception handler implementation uses setjmp() and longjmp() calls. If your application uses PC-DCE exception handling, the runtime library that you link to your application must provide a setjmp() and longjmp() implementation compatible with the Microsoft Visual C++ runtime. This includes the size and semantics of the jump buffer allocated for these calls.

2.2.4 Mapping WIN32 Exceptions to DCE Threads Exceptions

PC-DCE exception macros use WIN32 structured handling support by default to map WIN32 exceptions such as EXCEPTION_ACCESS_VIOLATION (winbase.h) to equivalent DCE threads exceptions (for example, in this case, to exc_e_illaddr).

As a side effect of this mapping, these exceptions are no longer propagated up via WIN32 structured exception handling to be handled by an external debugger. Non-production environments and environments that do not care about this mapping can disable this feature by calling the function __exc_w32_to_dce_map_set with an argument of 0 (false). This function, exported from dce32.dll and defined in dce/exc_handling.h, disables the mapping for the current process. You must call this function before executing any code block that uses PC-DCE exception handling.

2.3 Using OLE 2.0 with PC-DCE

OLE 2.0 supports distributed OLE calls which internally use the Microsoft RPC to handle the distributed part of OLE. OLE and DCE both define certain types (such as HANDLE_T and UUID_T) in their header files. If a source file includes both OLE and DCE header files, compile errors occur.

If you need to use OLE and DCE in your application, make sure you do the following:

2.4 Generating Stubs from the IDL Command Line

You can use the PC-DCE IDL compiler to generate stubs directly into object code from the IDL command line. For example, to run IDL and directly compile the generated stubs, use the following command:

prompt> 	idl -no_mepv -v -cc_opt "-nologo -I. -DWIN32_LEAN_AND_MEAN \
-DWIN32 -D_MT -D_DLL"

2.5 Using the Microsoft IDE Interface

To use the Microsoft IDE interface with PC-DCE applications:

  1. Add the following preprocessor definitions:

    WIN32
    WIN32_LEAN_AND_MEAN
    _MT
    _DLL

  2. Add install_directory\include and install_directory\include\dce and your current directory as Additional Include Directories.

  3. Add the install_directory\lib as a Library Directory.

  4. Add the dce32.lib library to your project.

  5. Compile your IDL file. Be sure to include the -keep c_source option to the IDL precompiler.

  6. Add the *_cstub.c or *_sstub.c file generated to your project.


[Previous] [Next] [Contents] [Index]


To make comments or ask for help, contact support@entegrity.com.

Copyright © 1997-2003 Entegrity Solutions Corporation & its subsidiaries