Главная страница | назад





Article #19400: How do I create a DLL in C++Builder3 that doesn't export the TDateTime class?

 Question and Answer Database

FAQ4400C.txt - How do I create a DLL in C++Builder3 that doesn't export the TDateTime class?

Category   :VCL
Platform   :All-32Bit
Product    :C++Builder3.x,   

Question:
When I create a DLL in C++Builder3 TDateTime is automatically exported. This
causes problems when I use this DLL in an application that uses TDateTime.
How do I create a DLL in C++Builder3 that doesn't export the TDateTime class?

Answer:
This is a bug in C++Builder3 that has been fixed in
C++Builder4. Below are two sample outputs from 'tdump'.
Notice that the DLL generated with C++Builder4 does not
export TDateTime:

From C++Builder3:
===========================================================
    0000    000015a4  Classes::TComponent::UpdateRegistry(bool,const System::AnsiString,const System::AnsiString) __fastcall
    0001    00001498  Forms::TForm::TForm(Classes::TComponent*) __fastcall
    0002    00001670  Forms::TForm::~TForm() __fastcall
    0003    00001868  System::DelphiInterface::~DelphiInterface() __fastcall
    0004    00001ac8  System::DelphiInterface::~DelphiInterface() __fastcall
    0005    000014f0  System::TDateTime::TDateTime() __fastcall
    0006    00001b54  Unit1::C21_4
    0007    00001b64  Unit1::C21_5
    0008    00001490  test()
    0009    0000357c  _Form1


From C++Builder4:
===========================================================
    0000    00001c98  ::Unit1::Finalize
    0001    00001c88  ::Unit1::Initialize
    0002    000015b4  Classes::TComponent::UpdateRegistry(bool,const System::AnsiString,const System::AnsiString) __fastcall
    0003    000014e0  Forms::TForm::TForm(Classes::TComponent*) __fastcall
    0004    0000167c  Forms::TForm::TForm(Classes::TComponent*) __fastcall
    0005    000016dc  Forms::TForm::~TForm() __fastcall
    0006    000014d8  foo()
    0007    0000357c  _Form1
    0008    00003236  ___CPPdebugHook
    0009    0000358c  ___dll_argc
    0010    00003590  ___dll_argv


In the C++Builder3 TDateTime is defined as:

   class DELPHIRETURN TDateTime : public TDateTimeBase

where DELPHIRETURN is:

   #define DELPHIRETURN            __declspec(delphireturn, package)

vs C++Builder4 where TDateTime is defined as:

   class RTL_DELPHIRETURN TDateTime;

where RTL_DELPHIRETURN is:

   // Macros specifically for C++ emulation of Delphi language features
   // Used for RTL functionality which should not be packaged.
   //
   #define RTL_DELPHIRETURN     __declspec(delphireturn)           // Uses Delphi's return semantic (not in package)

You can get around this problem by generating a .def
file from the DLL by typing:

   impdef Project1.def Project1.dll

Project1.def looks like this:

LIBRARY     PROJECT1.DLL

EXPORTS
    @Classes@TComponent@UpdateRegistry$qqr4boolx17System@AnsiStringxt2 @1   ; Classes::TComponent::UpdateRegistry(bool,const System::AnsiString,const System::AnsiString) __fastcall
    @Forms@TForm@$bctr$qqrp18Classes@TComponent @2   ; Forms::TForm::TForm(Classes::TComponent*) __fastcall
    @Forms@TForm@$bdtr$qqrv        @3   ; Forms::TForm::~TForm() __fastcall
    @System@%DelphiInterface$t14Forms@IOleForm%@$bdtr$qqrv @4   ; System::DelphiInterface::~IOleForm>() __fastcall
    @System@%DelphiInterface$t8IUnknown%@$bdtr$qqrv @5   ; System::DelphiInterface::~DelphiInterface() __fastcall
    @System@TDateTime@$bctr$qqrv   @6   ; System::TDateTime::TDateTime() __fastcall
    @Unit1@C21_4                   @7   ; Unit1::C21_4
    @Unit1@C21_5                   @8   ; Unit1::C21_5
    @test$qv                       @9   ; test()
    _Form1                         @10  


Note the line:

    @System@TDateTime@$bctr$qqrv   @6   ; System::TDateTime::TDateTime() __fastcall

You can then remove this line and run implib on the .def file:

   implib Project1.lib Project1.def

This will generate a .def file that you can link to in your other project.

5/25/99 11:45:39 AM
 

Last Modified: 01-SEP-99