13,826
社区成员
发帖
与我相关
我的任务
分享
void GetFormClass(TApplication* pApp, struct FormClass& f)
{
if(g_SavedApp == NULL)
{
g_SavedApp = Application;
}
Application = pApp;
f.ppForm = (TForm **)&FormDLL;
f.formClass = __classid(TFormDLL);
}
void WatchApplication(TApplication** pOutApp, unsigned int *pAddr)
{
//传入的Application和内部的Application的地址,以后外面做比对
char addr[15];
AnsiString outAddr, inAddr;
memset(addr, 0, 15);
sprintf(addr, "%#010X[1]", (unsigned int)*pOutApp);
outAddr = AnsiString(addr);
memset(addr, 0, 15);
sprintf(addr, "%#010X[2]", (unsigned int)Application);
inAddr = AnsiString(addr);
Common::log.Message(Format("[DLL内部] 传入的[%s]Application->MainForm->ActiveMDIChild->Caption %s",
ARRAYOFCONST((outAddr, (*pOutApp)->MainForm->ActiveMDIChild->Caption))));
Common::log.Message(Format("[DLL内部] 内部的[%s]Application->MainForm->ActiveMDIChild->Caption %s",
ARRAYOFCONST((inAddr, Application->MainForm->ActiveMDIChild->Caption))));
AnsiString outFormAddr, inFormAddr;
memset(addr, 0, 15);
sprintf(addr, "%#010X[1]", (unsigned int)(*pOutApp)->MainForm->ActiveMDIChild);
outFormAddr = AnsiString(addr);
memset(addr, 0, 15);
sprintf(addr, "%#010X[2]", (unsigned int)Application->MainForm->ActiveMDIChild);
inFormAddr = AnsiString(addr);
Common::log.Message(Format("[DLL内部] 传入的[%s]Application->MainForm->ActiveMDIChild地址 %s",
ARRAYOFCONST((outAddr, outFormAddr))));
Common::log.Message(Format("[DLL内部] 内部的[%s]Application->MainForm->ActiveMDIChild地址 %s",
ARRAYOFCONST((inAddr, inFormAddr))));
AnsiString formAddr;
memset(addr, 0, 15);
sprintf(addr, "%#010X", (unsigned int)FormDLL);
formAddr = AnsiString(addr);
Common::log.Message(Format("[DLL内部] 内部Form的地址 [%s]", ARRAYOFCONST((formAddr))));
*pAddr = (unsigned int)(*pOutApp)->MainForm->ActiveMDIChild;
memset(addr, 0, 15);
sprintf(addr, "%#010X", (unsigned int)*pAddr);
formAddr = AnsiString(addr);
Common::log.Message(Format("[DLL内部] 保存传入的[%s]Application->MainForm->ActiveMDIChild地址 [%s]",
ARRAYOFCONST((outAddr, formAddr))));
*pOutApp = Application;
}
struct FormClass f;
TApplication* pDll = Application; //将Application传入DLL中,再将DLL中的Application带出
unsigned int addr;
GETFORMCLASSFUNC Get
= (GETFORMCLASSFUNC)::GetProcAddress(m_dllIns, "_GetFormClass");
if(Get == NULL)
{
throw(Exception(Format("函数地址获取失败:%u", ARRAYOFCONST(((int)::GetLastError())))));
}
Get(Application, f);
if(f.ppForm == NULL)
{
return ;
}
if((*f.ppForm) == NULL)
{
Application->CreateForm(f.formClass, f.ppForm);
WATCHAPPFUNC WatchApp
= (WATCHAPPFUNC)::GetProcAddress(m_dllIns, "_WatchApplication");
if(WatchApp == NULL)
{
throw(Exception(Format("函数地址取址失败:%u", ARRAYOFCONST(((int)::GetLastError())))));
}
WatchApp(&pDll, &addr);
char address[15];
AnsiString outAddr, inAddr, formAddr;
memset(address, 0, 15);
sprintf(address, "%#010X[1]", (unsigned int)pDll);
outAddr = AnsiString(address);
memset(address, 0, 15);
sprintf(address, "%#010X[2]", (unsigned int)Application);
inAddr = AnsiString(address);
memset(address, 0, 15);
sprintf(address, "%#010X", (unsigned int)addr);
formAddr = AnsiString(address);
Common::log.Message(Format("[EXE] 传出的[%s]Application->MainForm->ActiveMDIChild->Caption %s",
ARRAYOFCONST((outAddr, pDll->MainForm->ActiveMDIChild->Caption))));
Common::log.Message(Format("[EXE] EXE的[%s]Application->MainForm->ActiveMDIChild->Caption %s",
ARRAYOFCONST((inAddr, Application->MainForm->ActiveMDIChild->Caption))));
Common::log.Message(Format("取得地址 [%s],强制显示地址中的Caption %s",
ARRAYOFCONST((formAddr, ((TForm *)addr)->Caption))));
}
(*f.ppForm)->Show();
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
}
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#include "Unit2.h" // TUserForm2 表单
extern "C" __declspec(dllexport)
TForm * __stdcall UserForm2Form(TComponent* Owner);
//---------------------------------------------------------------------------
#pragma argsused
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
TForm * __stdcall UserForm2Form(TComponent* Owner) // 传入主窗口 Application
{
TUserForm2 *CallForm = new TUserForm2(Owner);
CallForm->Show();
return CallForm;
}
//---------------------------------------------------------------------------