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.
{
// 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.
最好先分配内存,不要像delphi的使用习惯,直接用("c:\\asdf.exe");
我怀疑是不是没有找到这个函数啊 端点在int n=assertive("c:\\asdf.exe");一行 报错了
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.