我用VC2008 Qt开发的程序需要使用报表,就用Delphi 2009 做了个dll,将FastReport封装进去。
在调用测试时,最初使用LoadLibrary动态加载dll,没有任何问题。因为dll中函数较多,就改成静态链接。
结果每次退出程序时,出现:
Exeception EAccessViolation in module dbxmys.dll...我在 Delphi DLL中做了以下工作,仍然报错:
将ShareMem加到每个工作单元,包括project;
将borlndmm.dll复制到当前目录
去掉所有sharemem我在动态LoadLibrary时根本不使用ShareMem,也没有任何问题。我的DLL中只使用了LPCTSTR,根本不用string传参数。
由于代码太多,我贴出接口:
DLL:function OpenReportDB(pServerName,pDatabase,pUserName,pPassword:LPCTSTR): Bool; StdCall;
function CloseReportDB:Bool; StdCall;
function ReportPreview(parent:THandle; filePtr:LPCTSTR; sqlPtr:LPCTSTR):Bool; StdCall;
function ReportPrint(parent:THandle; filePtr:LPCTSTR;sqlPtr:LPCTSTR): Bool;  StdCall;
function VehicleReport(isPrint:BOOL):BOOL; StdCall;dpr中exports定义:
exports
  ReportPreview,
  ReportPrint,
  OpenReportDB,
  CloseReportDB,
  VehicleReport;C++中声明:
//静态调用 dll 的方法
extern "C" __declspec(dllimport) BOOL __stdcall OpenReportDB(LPWSTR,LPWSTR,LPWSTR,LPWSTR);//server,db,user,pwd
extern "C" __declspec(dllimport) BOOL __stdcall CloseReportDB(void);
extern "C" __declspec(dllimport) BOOL __stdcall ReportPreview(HWND,LPWSTR,LPWSTR);  //filename,sql
extern "C" __declspec(dllimport) BOOL __stdcall ReportPrint(HWND,LPWSTR,LPWSTR);    //filename,sql
extern "C" __declspec(dllimport) BOOL __stdcall VehicleReport(BOOL);    //isPrint
#pragma comment(lib,"report.lib")请问有何策略找出问题所在?