C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[65] builder 에서 MDI Child Form을 DLL로 만들어 쓰기...
정일권 [] 8771 읽음    2000-08-07 00:00
Dll 화일 내용

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

#include <vcl.h>
#include <windows.h>
#include "Unit2.h"
#pragma hdrstop

TApplication* DllApp = 0;
//---------------------------------------------------------------------------
//   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;
}
//---------------------------------------------------------------------------

extern "C" __declspec(dllexport) void __stdcall CreateChild(TApplication *App)
{
    if (!DllApp)
    {
        DllApp = Application;
        Application = App;
    }

    TForm2 *child = new TForm2(Application->MainForm);
    child->Show();
}

extern "C" __declspec(dllexport) void __stdcall ResetDllApp()
{
    if (DllApp)
    {
        Application = DllApp;
    }
}


Dll 안에 들어 있는 From 소스

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

#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::FormClose(TObject *Sender, TCloseAction &Action)
{
    Action = caFree;   
}
//---------------------------------------------------------------------------



Dll을 불러 들이는 Form (즉 MDI Parent 품)

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

#include <vcl.h>
#pragma hdrstop

#include "Unit21.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void (__stdcall *CreateChild)(TApplication *);
void (__stdcall *ResetDllApp)();
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    HINSTANCE DllInstance;
    DllInstance = LoadLibrary("Project1.dll");
    CreateChild = (void(__stdcall *)(TApplication *))GetProcAddress(DllInstance, "CreateChild");

    CreateChild(Application);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
    HINSTANCE DllInstance;
    DllInstance = LoadLibrary("Project1.dll");
    ResetDllApp = (void(__stdcall *)(void))GetProcAddress(DllInstance, "ResetDllApp");
    ResetDllApp();
}
//---------------------------------------------------------------------------

위 내용에 대한 나와있는곳이 없더군요...

저도 3주동안 고생해서 만든 소스입니다.


많은 도움이 되었으면 합니다. 그럼......
장성호 [nasilso]   2009-12-09 00:37 X
음.. 오래된 팁인데요..
혹 누군가가 참고할것 같아서 댓글 달아 봅니다.
---------------------------------------------
결론적으로 말씀드리면

Dll에 있는 Form-Class를 이용하여 MDI-Child폼을 만들려고 할때
위 방법은 가능은 하지만 문제가 많은 방법입니다.

메인폼에서 MDIChildrens배열에도 Dll의 폼이 추가되지 않으며..
그밖에도 여러가지 문제의 소지가 있습니다.
-----------------------------------------------------------
깔끔한 방법은 dll 및 exe둘다 run-time Package를 체크하여셔 컴파일 하면됩니다.
그러면 특별한 방법없이 그냥 exe에 있는 child-form을 생성하듯이
dll에서도 그냥 생성만 하면 mdi-child로 됩니다.

그럼..

+ -

관련 글 리스트
65 builder 에서 MDI Child Form을 DLL로 만들어 쓰기... 정일권 8771 2000/08/07
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.