BCB6主应用调用dll中的模块作为子窗口范例

直接上代码:

主应用动态调用DLL的代码

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   if( NULL == DLLInst ) DLLInst = LoadLibrary("Project1.dll"); //上面的 Dll
    if (DLLInst) { 
        Open = (void (__stdcall*)(TWinControl* parent,int GNID)) GetProcAddress(DLLInst,
                                                    "Open");
        if (Open)
        Open(Panel1,123);
        else
        ShowMessage("Could not obtain function pointer");
    }
    else ShowMessage("Could not load DLL.dll");      
}

dll中的头文件定义

Unit1.h

//---------------------------------------------------------------------------

#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#include <Unit2.cpp>
//---------------------------------------------------------------------------
//   Important note about DLL memory management when your DLL uses the
//   static version of the RunTime Library:
//
//   If your DLL exports any functions that pass String objects (or structs/
//   classes containing nested Strings) as parameter or function results,
//   you will need to add the library MEMMGR.LIB to both the DLL project and
//   any other projects that use the DLL.  You will also need to use MEMMGR.LIB
//   if any other projects which use the DLL will be performing new or delete
//   operations on any non-TObject-derived classes which are exported from the
//   DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
//   EXE's to use the BORLNDMM.DLL as their memory manager.  In these cases,
//   the file BORLNDMM.DLL should be deployed along with your DLL.
//
//   To avoid using BORLNDMM.DLL, pass string information using "char *" or
//   ShortString parameters.
//
//   If your DLL uses the dynamic version of the RTL, you do not need to
//   explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
        return 1;
}

//---------------------------------------------------------------------------
//作者:PMS动态库生成工具
//日期:2014年05月12日
//内容:生成标准的PMS接入DLL的接口函数
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) __stdcall void Open (TWinControl* parent)
{//打开动态库,在本函数中传递主程序接口类,并显示窗体
    TfrmMain = new TTfrmMain(parent);
    SetParent(TfrmMain->Handle, parent->Handle);
    ShowWindow ( TfrmMain->Handle, SW_SHOWMAXIMIZED );
    TfrmMain->Align = alClient;
    TfrmMain->Show();
}
dll中的子窗口。h文件

//---------------------------------------------------------------------------

#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TTfrmMain : public TForm
{
__published:	// IDE-managed Components
        TCheckBox *CheckBox1;
        TButton *Button1;
        void __fastcall Button1Click(TObject *Sender);
private:	// User declarations
public:		// User declarations
        __fastcall TTfrmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TTfrmMain *TfrmMain;
extern "C" __declspec(dllexport) __stdcall void Open (TWinControl* parent) ;
//---------------------------------------------------------------------------
#endif

下面的图片另存为之后改成rar后缀,解压后就得到源码:)



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值