beta : 您好,很遗憾没有通过 。代码如下 :
------------------------------------------------------
DLL :
library DLLDB;
uses
ShareMem,
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls,
DB,
ADODB;
{$R *.res}
const
DbConnectionString = 'Provider=SQLOLEDB.1;Persist Security Info=False;'
+ 'User ID=sa;Initial Catalog=Sms_Ga;Data Source=FRESHMAN ';
function Count(TableName: string): Integer; stdcall;
begin
with TADOQuery.Create(nil) do
begin
try
begin
ConnectionString := DbConnectionString;
Sql.Text := 'select count(*) from ' + TableName;
Open;
Result := RecordCount;
end;
finally
Free;
end;
end;
end;
Exports
Count ;
begin
end.
initialization
CoInitialize(Nil) ;
------------------------------------------------------
调用:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
function Count(TableName: string): Integer; stdcall;external 'F:/changshiF/DLL/DLL_数据库/DLLDB.dll' ;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(Count('reguser'))) ;
end;
提示还是 :[Error] DLLDB.dpr(56): Undeclared identifier: 'CoInitialize' 为什么呢?
我重启了几次了 ,难道在DLL中不能操作数据库 ? 不是呀 ? 该怎么作 ?
人在昆明 : 您好,Com 我还没有学 ,现在想学在DLL中操作数据库还有其他,你觉得为何
这样做会“把自己搞死” ? 望指导