呵呵呵呵呵

萝莉有三好,柔体 轻音 易推倒。女神有三宝,干嘛 呵呵 去洗澡。宅男有三好:Dota 基友 破电脑。


C++ Builder 2010创建基于VCL组件的DLL(动态库)

C++ Builder 2010创建基于VCL组件的DLL(动态库)


The code for the dialog box DLL is as follows:

// DLLMAIN.H
// ---------------------------------------------------------------------
#ifndef dllMainH
#define dllMainH
// ---------------------------------------------------------------------
#include <Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
 
// ---------------------------------------------------------------------
class TYesNoDialog : public TForm {
__published: // IDE-managed Components
 
    TLabel *LabelText;
    TButton *YesButton;
    TButton *NoButton;
 
    void __fastcall YesButtonClick(TObject *Sender);
    void __fastcall NoButtonClick(TObject *Sender);
 
private: // User declarations
 
    bool returnValue;
 
public: // User declarations
 
    virtual __fastcall TYesNoDialog(TComponent *Owner);
    bool __fastcall GetReturnValue();
};
 
// exported interface function
extern "C" __declspec(dllexport) bool InvokeYesNoDialog();
// ---------------------------------------------------------------------
extern TYesNoDialog *YesNoDialog;
// ---------------------------------------------------------------------
#endif
// DLLMAIN.CPP
// ---------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include "dllMain.h"
// ---------------------------------------------------------------------
#pragma resource "*.dfm"
TYesNoDialog *YesNoDialog;
 
// ---------------------------------------------------------------------
__fastcall TYesNoDialog::TYesNoDialog(TComponent *Owner) : TForm(Owner) {
    returnValue = false;
}
 
// ---------------------------------------------------------------------
void __fastcall TYesNoDialog::YesButtonClick(TObject *Sender) {
    returnValue = true;
    Close();
}
 
// ---------------------------------------------------------------------
void __fastcall TYesNoDialog::NoButtonClick(TObject *Sender) {
    returnValue = false;
    Close();
}
 
// ---------------------------------------------------------------------
bool __fastcall TYesNoDialog::GetReturnValue() {
    return returnValue;
}
 
// ---------------------------------------------------------------------
// exported standard C++ interface function that calls into VCL
bool InvokeYesNoDialog() {
    bool returnValue;
    TYesNoDialog *YesNoDialog = new TYesNoDialog(NULL);
    YesNoDialog->ShowModal();
    returnValue = YesNoDialog->GetReturnValue();
    delete YesNoDialog;
    return returnValue;
}

The code in this example displays the dialog and stores the value true in the private data member returnValue if the "Yes" button is pressed. Otherwise, returnValue is false. The public GetReturnValue() function retrieves the current value of returnValue.

To invoke the dialog and determine which button was pressed, the calling application calls the exported function InvokeYesNoDialog(). This function is declared in DLLMAIN.H as an exported function using C linkage (to avoid C++ name mangling) and the standard C calling convention. The function is defined in DLLMAIN.CPP.

By using a standard C function as the interface into the DLL, any calling application, whether or not it was created with C++Builder, can use the DLL. The VCL functionality required to support the dialog is linked into the DLL itself, and the calling application does not need to know anything about it.

Note that when creating a DLL that uses the VCL, the required VCL components are linked into the DLL resulting in a certain amount of overhead. The impact of this overhead on the overall size of the application can be minimized by combining several components into one DLL that only needs one copy of the VCL support components. 

更多内容:

VC/BCB 编程获取网卡当前的连接速度(带宽)
C++ Builder 2010 创建DLL动态库的方法
五类CAT5、超五类CAT5E、六类CAT6和超六类CAT6A四种布线方式系统性能差异
VC/BCB 获取其它进程HANDLE的三种方法
VC 获取PC的CPU,内存等信息示例代码

本文链接地址:http://www.hehehehehe.cn/i/699.html