library Project2;
uses
  SysUtils,
  Classes,
  Unit1 in 'Unit1.pas' {DataModule1: TDataModule};{$R *.res}
function GetValues(name:string):boolean;stdcall;
begin
DataModule1.Query1.Close;
 DataModule1.Query1.RequestLive:=true;
DataModule1.Query1.SQL.Text:='select *from TPower ';
DataModule1.Query1.Open;
if DataModule1.Query1.RecordCount>0 then
 begin
 Result:=true;
end
else begin
 Result:=false;
endend;
exports
   GetValues;
begin
end.
----------------------------------
unit Unit2;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
  type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
  function GetValues(name:string): boolean; stdcall;
var
  Form1: TForm1;implementation
  {$R *.dfm}
   function GetValues; external 'D:\testforPower\1_2\Project2.dll' name 'GetValues';
procedure TForm1.Button1Click(Sender: TObject);
begin
if     GetValues('aaa')=true then
begin
   Edit1.Text:='right';
   end
   else begin
    Edit1.Text:='false';
    end
end;end.
------------------
可是一点按钮就提示:Access violation at address 0027BD85 in module 'project2.dll',Read of address 00000058,这要怎莫改呀?

解决方案 »

  1.   

    我主要是想做一个dll,专门处理用户权限,有权限就返回true。其他人都可以调用这个dll来做判断!还有我的数据库是sql server,有密码,和这个有关吗?
      

  2.   

    需要初始化:(错误的原因是datamodule没有创建)
    uses
      ActiveX,
    //...
    //...
      uDMPSet in 'uDMPSet.pas' {DMPrintSet: TDataModule};{$R *.res}var
      NewHandle,OldHandle:TApplication;procedure tSet(Proc: DWord);
    begin
      case Proc of
        DLL_PROCESS_ATTACH:
        begin
          CoInitialize(nil);
          DMPrintSet := TDMPrintSet.Create(nil);
          NewHandle := nil;
          OldHandle := Application;
        end;
        DLL_PROCESS_DETACH:
        begin
          CoUnInitialize;
          DMPrintSet.Free ;
          Application := OldHandle;
        end;
        DLL_THREAD_ATTACH:
        begin    end;
        DLL_THREAD_DETACH:
        begin    end;
      end;
    end;
    //...//...begin
      DllProc := @tSet;
      tSet(DLL_PROCESS_ATTACH);
    end.
      

  3.   

    CoUnInitialize;
    [Error] Project2.dpr(34): Missing operator or semicolon
      

  4.   

    是不是这意思?
    uses
      ActiveX,SysUtils,
      Classes,
      Unit1 in 'Unit1.pas' {DataModule1: TDataModule};{$R *.res}
    function GetValues(name:string):boolean;stdcall;
    begin
    CoInitialize(nil);DataModule1.Query1.Close;
     DataModule1.Query1.RequestLive:=true;
    DataModule1.Query1.SQL.Text:='select *from TPower ';
    DataModule1.Query1.Open;
    if DataModule1.Query1.RecordCount>0 then
     begin
     Result:=true;
    end
    else begin
     Result:=false;
    end
    activex.CoUninitialize;end;
    exports
       GetValues;
    beginend.
    不过还是上边的错误!
      

  5.   

    upMask(up用的马甲) 
    我讨厌你的名字!