C++ Builder MDi程序中 通过DLL调用窗体

  • A7_314742
    了解作者
  • 1.9KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-27 01:41
    上传日期
C++ Builder MDi程序中 通过DLL封装子窗体,
dll.rar
  • dll.c
    7.4KB
内容介绍
经过各位大虾的帮助,我实现了在fsMDIForm中调用DLL中的fsMDIChild。下面全部示例代码。 DLL部分: 先用DLL向导生成一个DLL项目Project1,对应Unit1.cpp,并在项目中Add一个窗体Form2,对应Unit2。 //Unit1.cpp //------------------------------------------------------------------------ #include <vcl.h> #include <windows.h> #include <activeX.hpp rel='nofollow' onclick='return false;'> //手工加入ActivateX.hpp #include "Unit2.h " //手工加入Unit2 #pragma hdrstop //------------------------------------------------------------------------ // 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 //------------------------------------------------------------------------ extern "C " __declspec(dllexport) void __stdcall ShowForm(TApplication *CallingApp);//手工加上导出函数 #pragma argsused void __stdcall ShowForm(TApplication *CallingApp) //新增导出函数 { Application=CallingApp; TForm2 *Form2=new TForm2(Application); Form2-> Show(); } int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) { switch(reason) //手工增加 { case DLL_PROCESS_ATTACH: CoInitialize(NULL);break; case DLL_PROCESS_DETACH: CoUninitialize();Application=NULL;break; } return 1; } //------------------------------------------------------------------------ Unit2.h //把FormStyle设置成fsMDIChild,并在Form2上放置了一些控件 //------------------------------------------------------------------------ #ifndef Unit2H #define Unit2H //------------------------------------------------------------------------ #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <aDODB.hpp rel='nofollow' onclick='return false;'> #include <DB.hpp> #include <ExtCtrls.hpp> //------------------------------------------------------------------------ class TForm2 : public TForm { __published: // IDE-managed Components TLabel *Label1; TButton *Button1; TADOTable *ADOTable1; TPanel *Panel1; TPanel *Panel2; TEdit *Edit1; void __fastcall Button1Click(TObject *Sender); void __fastcall FormClose(TObject *Sender, TCloseAction &Action); private: // User declarations public: // User declarations __fastcall TForm2(TComponent* Owner); }; //------------------------------------------------------------------------ extern PACKAGE TForm2 *Form2; //--------------------------------------------------------------------------- #endif Unit2.cpp //------------------------------------------------------------------------ #include <vcl.h> #pragma hdrstop #include "Unit2.h " //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm " TForm2 *Form2; //------------------------------------------------------------------------ __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm2::Button1Click(TObject *Sender) { Close(); } //------------------------------------------------------------------------ void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action) { Action=caFree; } //------------------------------------------------------------------------ 主程序ExE文件由Project2和Unit3组成。调用DLL分成静态和动态两种方式 Unit3.h 把FormStyle设置成fsMDIForm //------------------------------------------------------------------------ #ifndef Unit3H #define Unit3H //------------------------------------------------------------------------ #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> //------------------------------------------------------------------------ class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; TButton *Button2; void __fastcall Button1Click(TObject *Sender); void __fastcall Button2Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //------------------------------------------------------------------------ extern PACKAGE TForm1 *Form1; //------------------------------------------------------------------------ #endif Unit3.cpp //------------------------------------------------------------------------ #include <vcl.h> #pragma hdrstop #include "Unit3.h " //------------------------------------------------------------------------ #pragma package(smart_init) #pragma resource "*.dfm " extern "C " __declspec(dllexport) void __stdcall ShowForm(TApplication *CallingApp); HINSTANCE inst=NULL; TForm1 *Form1; //------------------------------------------------------------------------ __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //------------------------------------------------------------------------ void __fastcall TForm1::Button1Click(TObject *Sender) ///动态调用DLL { void (__stdcall *LoadDLL)(TApplication*)=NULL; inst=LoadLibrary( "Project1.DLL "); if (inst) { (FARPROC)LoadDLL=GetProcAddress(inst, "ShowForm "); if (LoadDLL) LoadDLL(Application); } } //------------------------------------------------------------------------ void __fastcall TForm1::Button2Click(TObject *Sender) ///静态调用DLL { ShowForm(Application); } //------------------------------------------------------------------------
评论
    相关推荐
    • C++ Primer
      C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。 对C++基本概念和技术全面而且权威的阐述,对...
    • c++课件
      c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件
    • C++
      C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++
    • Effective C++
      学习c++的经典书籍!每一个学习c++的人有时间最好看看!你会获得很大收获!
    • C++ primer
      本文档具有C++ primer 以及 C++ primer 标准答案各一份,内容清晰充实!希望与热爱C++的学友们一起同舟共济,努力学习!
    • c++information
      c++c++c++c++c++c++c++c++c++c++c++c++
    • SourceStyler C++
      用DEV-C++写代码很方便,就是不能格式化有点郁闷 c++格式化的好工具 效率高
    • c++yuyanbiancheng
      这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!
    • effective C++
      有关C++编程方面的检验性介绍,对由C转向C++,和有C++编程基础的程序员有帮助,不过是英文版
    • C++ Primer
      本书是久负盛名的C++经典教程引,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++