在D环境中调用DLL不报错,脱离D环境就报错.好象是内存出错,调不出窗口.以下是DLL内容.请查证!(50分)

  • 主题发起人 主题发起人 ccponline
  • 开始时间 开始时间
C

ccponline

Unregistered / Unconfirmed
GUEST, unregistred user!
library BaseFileDll;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
// ShareMem ,
Windows,
Forms,
SysUtils,
Classes,
Dialogs,
Messages,
Controls,
ADODB,
DataModuleBase in 'DataModuleBase.pas' {DmBase: TDataModule},
Bank in 'Bank.pas' {frmBank},
Variable in '../public.pas/Variable.pas',
Bios in '../public.pas/Bios.pas',
CommonFunc in '../public.pas/CommonFunc.pas',
frmselectitem in '../public.pas/frmselectitem.pas' {fmselectitem},
md5 in '../public.pas/md5.pas',
PubCourse in '../public.pas/PubCourse.pas',
PubFunction in '../public.pas/PubFunction.pas',
PubFuncUnit in '../public.pas/PubFuncUnit.pas',
PubProCess in '../public.pas/PubProCess.pas',
BaseFile in 'BaseFile.pas' {frmBaseFile},
Customer in 'Customer.pas' {frmCustomer},
CustomerE in 'CustomerE.pas' {frmCustomerE},
CusClass in 'CusClass.pas' {frmCusClass},
Dept in 'Dept.pas' {frmDept},
ZgdaEt in 'ZgdaEt.pas' {frmZgdaEt},
Zgda in 'Zgda.pas' {frmZgda},
UN_Bank in 'UN_Bank.pas' {frmUN_Bank},
UN_Bank_E in 'UN_Bank_E.pas' {frmUN_Bank_E},
DistrictClass in 'DistrictClass.pas' {frmDistrictClass},
TradeClass in 'TradeClass.pas' {frmTradeClass},
MeasureUnit in 'MeasureUnit.pas' {frmMeasureUnit},
Rd_Style in 'Rd_Style.pas' {frmRd_Style},
PurchaseType in 'PurchaseType.pas' {frmPurchaseType},
SaleType in 'SaleType.pas' {frmSaleType},
Position in 'Position.pas' {frmPosition},
Storehouse in 'Storehouse.pas' {frmStorehouse},
InventoryClass in 'InventoryClass.pas' {frmInventoryClass},
Inventory in 'Inventory.pas' {frmInventory},
InventoryE in 'InventoryE.pas' {frmInventoryE},
EXCH in 'EXCH.pas' {frmEXCH},
VendorE in 'VendorE.pas' {frmVendorE},
VenClass in 'VenClass.pas' {frmVenClass},
Vendor in 'Vendor.pas' {frmVendor},
SettleStyle in 'SettleStyle.pas' {frmSettleStyle},
u_xgmm in 'U_XGMM.PAS' {frmXgmm},
CM_Type in 'CM_Type.pas' {frmCM_Type},
UseManger in 'UseManger.pas' {frmUseManger},
UseMangerE in 'UseMangerE.pas' {frmUseMangerE},
CM_TypeClass in 'CM_TypeClass.pas' {frmCM_TypeClass};

// procedure ShowModal(aFormClass: TFormClass); //调用窗口
var
// DLLApp: TApplication;
DllApplication: TApplication;
SaveExit:Pointer ;
{$R *.res}
procedure ShowMdiForm(AHandle: THandle;indexs:Integer;const userAliasName,UserName,uFullName:ShortString;ConnectionString:WideString);export;stdcall;
var
OldHandle:THandle;
// DllProc: Pointer;
procedure freenil;
begin
Application.Handle:=OldHandle;
DmBase.ADOconADOConBase.Connected :=False ;
DmBase.Free ;
DmBase:=nil;
end;

procedure showmodalfrmDept; //部门
begin
Application.Handle := AHandle;
frmdept:=TfrmDept.Create(Application);
try
frmdept.ShowModal ;
finally
FreeAndNil(frmdept) ;
end;
end;

procedure showmodalfrmZgda; //职工
begin
Application.Handle := AHandle;
frmZgda:=TfrmZgda.Create(Application);
try
frmZgda.ShowModal ;
finally
//frmZgda.Free ;
FreeAndNil(frmZgda);
end;
end;


procedure ShowModal(aFormClass: TFormClass); //调用窗口 TFormClass
begin
screen.Cursor := crHourGlass;
with aFormClass.Create(Application) do begin
screen.Cursor := crDefault;
try
showModal;
finally
// Application.Handle:=OldHandle;
free;
end;
end;
end;

begin
Oldhandle:=Application.Handle;
// Application:=ParentApplication;
Application.Handle:=AHandle;
cCreatePerson:=UserName;
CurrentParam.userAliasName := userAliasName;
CurrentParam.UserName:= UserName;
CurrentParam.uFullName:= uFullName;
MainDir:=ExtractFilePath(Application.Exename);
if copy(MainDir,length(MainDir),1)<>'/'
then MainDir:=MainDir+'/';
Application.CreateForm(TDmBase, DmBase);
DmBase.ADOconADOConBase.Connected :=False ;
DmBase.ADOconADOConBase.ConnectionString :=ConnectionString;
DmBase.ADOconADOConBase.Connected :=True;
case indexs of
0:showmodalfrmDept;
1: showmodalfrmZgda ;
2:ShowModal(TfrmCusClass);
3:ShowModal(TfrmCustomer);
4:ShowModal(TfrmVenClass);
5:ShowModal(TfrmVendor);
6:ShowModal(TfrmBank);
7:ShowModal(TfrmUN_Bank);
8:ShowModal(TfrmDistrictClass);
9:ShowModal(TfrmTradeClass);
10:ShowModal(TfrmMeasureUnit);
11:ShowModal(TfrmPurchaseType);
12:ShowModal(TfrmRd_Style);
13:ShowModal(TfrmSaleType);
14:ShowModal(TfrmStorehouse);
15:ShowModal(TfrmPosition);
16:ShowModal(TfrmInventoryClass);
17:ShowModal(TfrmInventory);
18:ShowModal(TfrmEXCH);
19:ShowModal(TfrmSettleStyle);
20:ShowModal(TfrmCM_TypeClass);
21:ShowModal(TfrmUseManger);
22:ShowModal(TfrmCM_Type);
99:ShowModal(TfrmXgmm);
end;

freenil;//释放数据模块

end;

procedure DLLUnloadProc(Reason: Integer); register;
begin
if (Reason = DLL_PROCESS_DETACH) or (Reason = DLL_THREAD_DETACH) then
begin
Application := DllApplication; //DLLApp;
//DLLApp是在DLL工程文件中定义的全局TApplication对象
//用来保存Application对象
SendMessage(Application.Handle, WM_CLOSE, 0, 0);
FreeLibrary(Application.Handle);
end;
end;


procedure LibExit;
begin
ExitProc :=SaveExit ;
end;

exports
ShowMdiForm;


begin
//DLLApp := Application; //保存 DLL 中初始的 Application 对象
DllApplication:=Application;
DLLProc := @DLLUnloadProc; //保证 DLL 卸载时恢复原来的 Application
SaveExit :=ExitProc ;
ExitProc :=@LibExit;
end.
 
把borlndmm.dll文件拷至程序文件夹中试试
 
没有用...同样出错!
 
以下是我写的一个商业程序的代码,没问题,你参考一下了
library BaseInfo;

uses
Forms,
Windows,
MainDataSQLUnit in '../../MainDataSQLUnit.pas',
MainDataType in '../../MainDataType.pas',
MainSysUtils in '../../MainSysUtils.pas',
MsgBoxUnits in '../../MsgBoxUnits.pas',
MainConsts in '../../MainConsts.pas',
QueryParaFrm in '../../QueryParaFrm.pas' {QueryParaForm},
DataFindFrm in '../../DataFindFrm.pas' {DataFindForm},
BrandInfoFrm in 'BrandInfoFrm.pas' {BrandInfoForm},
BrandModifyFrm in 'BrandModifyFrm.pas' {BrandModifyForm},
BaseInfoDataModuleFrm in 'BaseInfoDataModuleFrm.pas' {BaseInfoDataModule: TDataModule},
CommonUseWordFrm in 'CommonUseWordFrm.pas' {CommonUseWordForm},
ClassInfoFrm in 'ClassInfoFrm.pas' {ClassInfoForm},
ClassModifyFrm in 'ClassModifyFrm.pas' {ClassModifyForm},
CommodityInfoFrm in 'CommodityInfoFrm.pas' {CommodityInfoForm},
CommodityModifyFrm in 'CommodityModifyFrm.pas' {CommodityModifyForm},
ToponymModifyFrm in 'ToponymModifyFrm.pas' {ToponymModifyForm},
ToponymInfoFrm in 'ToponymInfoFrm.pas' {ToponymInfoForm},
ClientInfoFrm in 'ClientInfoFrm.pas' {ClientInfoForm},
ClientModifyFrm in 'ClientModifyFrm.pas' {ClientModifyForm},
ColorInfoFrm in 'ColorInfoFrm.pas' {ColorInfoForm},
ColorModifyFrm in 'ColorModifyFrm.pas' {ColorModifyForm},
EmployeeInfoFrm in 'EmployeeInfoFrm.pas' {EmployeeInfoForm},
EmployeeModifyFrm in 'EmployeeModifyFrm.pas' {EmployeeModifyForm},
FactoryModifyFrm in 'FactoryModifyFrm.pas' {FactoryModifyForm},
FactoryInfoFrm in 'FactoryInfoFrm.pas' {FactoryInfoForm},
CommonUseWordModifyFrm in 'CommonUseWordModifyFrm.pas' {CommonUseWordModifyForm};

{$R *.res}

var
DLLApplication: TApplication;
DllScreen: TScreen;

procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApplication;
Screen := DllScreen;
end;
end;

exports
CommodityInfo,
BrandInfo,
ColorInfo,
ToponymInfo,
ClassInfo,
EmployeeInfo,
ClientInfo,
FactoryInfo,
CommonUseWord;

begin
DLLApplication := Application;
DllScreen := Screen;
DLLProc := @ExitDLL;
end.
 
后退
顶部