void CTeDlg::OnOK() 
{
// TODO: Add extra validation here
HINSTANCE hInstance=::LoadLibrary("assertive.dll");
if(NULL!=hInstance)
{
typedef int(__stdcall *MYFARPROC)(LPSTR szPathName); 
MYFARPROC assertive=(MYFARPROC)GetProcAddress(hInstance,"assert");
int n=assertive("c:\\asdf.exe");
if(1==n)
{
MessageBox("yes,you can!");
}else{
MessageBox("no,you can not");
}
return;
FreeLibrary(hInstance);
}else{
    CHAR szBuf[80]; 
DWORD dw = GetLastError();  
sprintf(szBuf, "failed: GetLastError returned %u\n", dw);  
MessageBox(szBuf); 
FreeLibrary(hInstance);
}// CDialog::OnOK();
}library assertive;{ 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
  SysUtils,
  Classes;{$R *.res}function assert(szPathName:PChar):Integer;stdcall;
begin
if szPathName<>'' then begin
result:=1;
end else begin
result:=0;
end;
end;exports
assert;begin
end.

解决方案 »

  1.   

    LPSTR szPathName试下用 char * 看看
    最好先分配内存,不要像delphi的使用习惯,直接用("c:\\asdf.exe");
      

  2.   

    什么错?除了if szPathName<>'' then begin判断有问题之外。
      

  3.   

    换了char*还是不行啊  调试运行提示 unhandled exception in test.exe(KENEL32.DLL):0x0EEDFADE:()no name.    
    我怀疑是不是没有找到这个函数啊   端点在int n=assertive("c:\\asdf.exe");一行  报错了
      

  4.   

    建议你改名,Delphi中有一个Assert的procedure,也许......
      

  5.   

    这是原先的dll体,我刚才试验了半天 确定是这个delphi的dll有问题  大家帮忙看看怎么回事?library assertive;{ 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
      SysUtils,
      Classes,
      SQLite3 in 'SQLite3.pas',
      SQLiteTable3 in 'SQLiteTable3.pas',
      Forms,
      Share in 'Share.pas';{$R *.res}function assertive_crc32(szPathName:PChar):Integer;stdcall;
    var dbPath,PathCRC32:string;
        szAccessProc:TStringList;
        sldb: TSQLiteDatabase;
        sltb: TSQLIteTable;
        i,j,crc32:integer;
    begin
      crc32:=GetCRC32Value(szPathName);
      PathCRC32:=IntToStr(crc32);
      dbPath:=ExtractFilepath(Application.ExeName)+('Sqlite.db');
      szAccessProc:=TStringList.Create;
      sldb:=TSQLiteDatabase.Create(dbPath);
      sltb:=sldb.GetTable('SELECT * FROM S_MAPPATHCRC32');
      while not sltb.EOF do begin
      for i:=0 to sltb.RowCount-1 do begin
        szAccessProc.Add(sltb.FieldAsString(sltb.FieldIndex['ulPathCrc32']));
        sltb.Next;
      end;
      end;
      if  szAccessProc.Count<>0 then begin
        for j:=0 to szAccessProc.Count-1 do begin
          if PathCRC32=szAccessProc.Strings[j] then begin
            result:=0;
            Exit;
          end else if j=szAccessProc.Count-1 then begin             
            result:=1;
            Exit;
          end;
        end;
      end else begin
        result:=1;
        Exit;
      end;
      result:=1;
    end;exports
    assertive_crc32;begin
    end.
      

  6.   

    你用delphi打开这个dll,设置run-parameters里的host application为调用dll的这个exe。然后在dll里设置断点调试一下,看看哪句的问题!
      

  7.   

    你传递的参数是PChar时,需要在DLL工程的uses里面第一个加上BorlandMM单元。而且要复制Delphi X/bin下面的BorlandMM.dll到你DLL的同一目录下面。