Show: Delphi C++
Display Preferences

Creating DLLs in C++Builder

From RAD Studio
Jump to: navigation, search

Go Up to Creating Packages and DLLs


Creating DLLs in C++Builder is the same as in standard C++:

  1. Choose File > New > Other to display the New Items dialog box.
  2. Double-click the DLL Wizard icon.
  3. Choose the Source type (C or C++) for the main module.
  4. If you want the DLL entry point to be DllMain, MSVC++style, check the VC++style option. Otherwise, DllEntryPoint is used for the entry point.
  5. If you want the DLL to be multi-threaded, check the Multi-threaded option.
  6. Click OK.

Exported functions in the code should be identified with the __declspec(dllexport) modifier as they must be in Embarcadero C++ or Microsoft Visual C++.

For example, the following code is legal in C++Builder and other Windows C++ compilers:

// MyDLL.cpp
double dblValue(double);
double halfValue(double);
extern "C" __declspec(dllexport) double changeValue(double, bool);
 
double dblValue(double value) {
	return value * value;
};
 
double halfValue(double value) {
	return value / 2.0;
}
 
double changeValue(double value, bool whichOp) {
	return whichOp ? dblValue(value) : halfValue(value);
}

In the code above, the function changeValue is exported, and therefore made available to calling applications. The functions dblValue and halfValue are internal, and cannot be called from outside of the DLL.

Additional information on creating DLLs can be found in the Win32 MSDK Reference.

See Also

Personal tools
In other languages
Previous Versions
Assistance