调用DLL的问题(100)

  • 主题发起人 主题发起人 lixianxiang
  • 开始时间 开始时间
L

lixianxiang

Unregistered / Unconfirmed
GUEST, unregistred user!
我直接引用单元文件,调用Pvt_ExportDBGrid执行正常,而采用静态调用DLL,就会出错:Ole error 800A03EC什么原因?麻烦高手指教下,谢谢了代码如下:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;type TForm1 = class(TForm) ADOConnection1: TADOConnection; DBGrid1: TDBGrid; ADOTable1: TADOTable; DataSource1: TDataSource; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation// uses Functions;procedure Pvt_ExportDBGrid(ADBGrid: TDBGrid; AStartRowNo: Integer); stdcall; external 'MyDLL.dll';procedure Pvt_ShowMessage; stdcall; external 'MyDLL.dll';procedure Pvt_EndProcess(AFileName: string); stdcall; external 'MyDLL.dll';{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin Pvt_ShowMessage; try Pvt_ExportDBGrid(DBGrid1, 2); except Pvt_EndProcess('EXCEL.EXE');// raise; end; end;end.MyDLL如下:library MyDLL;uses SysUtils, Classes, Functions in 'Functions.pas';exports Pvt_ExportDBGrid, Pvt_EndProcess, Pvt_CheckNUMOnKeyPress, Pvt_CheckNUMOnExit, Pvt_ColNumToChar, Pvt_ShowMessage;{$R *.res}beginend.
 
DLL代码提供不完整,试试看下面的方法,在DLL工程文件的begin..end中添加一行代码: ActiveX.CoInitialize(Nil);需要use ActiveX;
 
Functions.pas中Pvt_ExportDBGrid如下:procedure Pvt_ExportDBGrid(ADBGrid: TDBGrid; AStartRowNo: Integer);var Lv_ExApp, Lv_ExBook, Lv_ExSheet: Variant; Lv_Row, Lv_Col: Integer; procedure Pvt_FillARowCells(ARowNO: Integer); var Lv_ColNO: Integer; begin for Lv_ColNO := 1 to ADBGrid.Columns.Count do begin if ADBGrid.Columns[Lv_ColNO - 1].Field is TFloatField then Lv_ExSheet.Cells[ARowNO, Lv_ColNO] := ADBGrid.Columns[Lv_ColNO - 1].Field.AsString else Lv_ExSheet.Cells[ARowNO, Lv_ColNO] := '''' + ADBGrid.Columns[Lv_ColNO - 1].Field.AsString; end; end;begin if not ADBGrid.DataSource.DataSet.Active then Exit; Lv_ExApp := CreateOleObject('Excel.Application'); Lv_ExBook := Lv_ExApp.WorkBooks.Add; Lv_ExSheet := Lv_ExBook.WorkSheets.Item[1]; Lv_Row := AStartRowNo; Screen.Cursor := crHourGlass; for Lv_Col := 1 to ADBGrid.Columns.Count do begin Lv_ExSheet.Cells[Lv_Row, Lv_Col] := ADBGrid.Columns[Lv_Col - 1].Title.Caption; end; //Lv_ExSheet.Cells.NumberFormatLocal := '@'; Inc(Lv_Row); ADBGrid.DataSource.DataSet.DisableControls; with ADBGrid.DataSource.DataSet do begin First; while not Eof do begin Pvt_FillARowCells(Lv_Row); Inc(Lv_Row); Next; end; First; end; ADBGrid.DataSource.DataSet.EnableControls; Lv_ExSheet.Cells.Columns.AutoFit; Lv_ExSheet.Cells.Font.Size := 10; Lv_ExApp.Visible := True; Screen.Cursor := crDefault;end;加上你说的那行代码,还是同样的错误。为什么,我直接引用单元文件,调用Pvt_ExportDBGrid,执行就正常,采用调用DLL就有问题?
 
我知道了,Functions.pas中Pvt_ExportDBGrid申明时,加上stdcall如下:procedure Pvt_ExportDBGrid(ADBGrid: TDBGrid; AStartRowNo: Integer); stdcall;
 
那你的分怎么办?呵呵,谢谢哦!
 
没人进来,那分就给你算了,呵呵
 

Similar threads

I
回复
0
查看
628
import
I
I
回复
0
查看
633
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
672
import
I
后退
顶部