Creating C++ DLL


 * TN1001

This example creates a class called base in testdll.cpp which is placed into a DLL.

Main in sample.c instantiates class base and calls a function in base to print out a message. C++ exception handling from a DLL is demonstrated by having the function do a throw which is caught in a catch block in main.

Mangled names apprear in the IMPORT section of sample.def below.
 * 1) use "cppfilt /B /P sample.obj" to dump mangled names
 * 2) build a library using sample.obj and get a listing using lib.exe
 * 3) there are some utilities programs available that can dump obj names

SOURCE
class base { public: void func(void); ~base(void); class bomb{ public: bomb(int i) { } }; };
 * dlltest.hpp

base::~base(void) { printf("in base destructor\n"); } void base::func(void) { printf("in base func\n"); throw bomb(1); }
 * dlltest.cpp
 * 1) include 
 * 2) include "dlltest.hpp"
 * 1) pragma export(base::func(void))
 * 2) pragma export(base::~base(void))

LIBRARY DLLTEST INITINSTANCE DESCRIPTION 'Classes Dynamic Linking library' PROTMODE DATA       MULTIPLE READWRITE LOADONCALL CODE       LOADONCALL
 * dlltest.def

void main {   base *b = new base; printf("after new\n"); try { b->func; }   catch (base::bomb x) { printf("caught\n"); }  printf("after d->func\n"); delete b;  printf("after delete b\n"); }
 * sample.cpp
 * 1) include 
 * 2) include "dlltest.hpp"

NAME SAMPLE WINDOWCOMPAT IMPORTS dlltest.__dt__4baseFv dlltest.func__4baseFv
 * sample.def

COMPILE OPTIONS
icc -Gm+ -Fd -Ge- dlltest.cpp dlltest.def icc -Gm+ -Fd      sample.cpp sample.def

various combinations of -Gd+ -Gm are possible depending on the desired configuration.

OUTPUT
after new in base func caught after d->func in base destructor after delete b