P
pcsHP
Unregistered / Unconfirmed
GUEST, unregistred user!
但如果用CB6编译动态库能正常调用,且子窗口能正常显示。初步估计Delphi7和CB5的VCL内核不一样,例如:接口函数OpenForm(aMainForm:TForm),则在D7中将主窗口MainForm传入后,跟踪动态库创建窗口时就报异常。郁闷了好几天了,麻烦那位高人救我于水深火热之中,多谢了。
CB的接口定义
int __declspec(dllexport) __stdcall OpenForm(TForm* AMainForm);
-------CBuilder的代码-----
int __stdcall OpenForm(TForm* AMainForm)
{
TForm **temp;
//因MainForm 为指向指针的指针
temp = &(Application->MainForm);
*temp = AMainForm;
TForm3 *Form3 = new TForm3(AMainForm);
Form3->Show();
/*var
Form1: TForm1;
ptrLongInt;
begin
ptr:=@(Application.MainForm);//先把dll的MainForm句柄保存起来,也无须释放,只不过是替换一下
ptr^:=LongInt(mainForm);//用主调程序的mainForm替换DLL的MainForm。MainForm是特殊的WINDOW,它专门管理Application中的Forms资源.
//为什么不直接Application.MainForm := mainForm,因为Application.MainForm是只读属性
Form1:=TForm1.Create(mainForm);//用参数建立
*/
return 1;
}
-------------------
------主窗口Delphi调用代码---
procedure TMainForm.Button4Click(Sender: TObject);
var
OpenForm: procedure(AForm:TForm);stdcall;
begin
@OpenForm := GetprocAddress(pxx(fDllList[maxdll]).Handle, 'OpenForm');
if @OpenForm = NIL then
begin
MessageBox(Handle, pchar('Could Not Found Entry:OpenForm'), 'Error', 0);
Exit;
end;
OpenForm(Application.MainForm);
end;
-------------------
CB的接口定义
int __declspec(dllexport) __stdcall OpenForm(TForm* AMainForm);
-------CBuilder的代码-----
int __stdcall OpenForm(TForm* AMainForm)
{
TForm **temp;
//因MainForm 为指向指针的指针
temp = &(Application->MainForm);
*temp = AMainForm;
TForm3 *Form3 = new TForm3(AMainForm);
Form3->Show();
/*var
Form1: TForm1;
ptrLongInt;
begin
ptr:=@(Application.MainForm);//先把dll的MainForm句柄保存起来,也无须释放,只不过是替换一下
ptr^:=LongInt(mainForm);//用主调程序的mainForm替换DLL的MainForm。MainForm是特殊的WINDOW,它专门管理Application中的Forms资源.
//为什么不直接Application.MainForm := mainForm,因为Application.MainForm是只读属性
Form1:=TForm1.Create(mainForm);//用参数建立
*/
return 1;
}
-------------------
------主窗口Delphi调用代码---
procedure TMainForm.Button4Click(Sender: TObject);
var
OpenForm: procedure(AForm:TForm);stdcall;
begin
@OpenForm := GetprocAddress(pxx(fDllList[maxdll]).Handle, 'OpenForm');
if @OpenForm = NIL then
begin
MessageBox(Handle, pchar('Could Not Found Entry:OpenForm'), 'Error', 0);
Exit;
end;
OpenForm(Application.MainForm);
end;
-------------------