静态调用:
function GolayCode(lpBuffer: PChar; uSize: UINT; Result: PChar): UINT; stdcall; external 'code_dll.dll'
程序中直接调用该函数即可。
动态调用:
procedure TForm1.Button1Click(Sender: TObject);
//const cc:array[0..4]of byte=($1,$2,$3,$4,$5);
var
//buffer: pchar;
data, result: array[0..512]of char;
h : HInst;
fn, fn2 : function (lpBuffer: PChar; uSize: UINT; Result: PChar): UINT; stdcall;
pn: procedure;stdcall;
//fs:LPCSTR;
c_len, d_len, i: integer;
s, s2: string;
begin
h:=LoadLibrary('code_dll.dll');
if h=0 then
begin
showMessage('load library error!');
exit;
end;
@fn := GetProcAddress(h,Pchar('golay_code'));
@fn2 := GetProcAddress(h,Pchar('golay_decode'));
@pn := GetProcAddress(h,Pchar('generate_golay_table'));
if (@fn=nil)or(@pn=nil) then
begin
showMessage('get proc address error!');
freelibrary(h);
exit;
end;
data := '12345';
//getmem(buffer,512);
pn;
c_len := fn(data,5,result);
d_len := fn2(result,c_len,data);
s := '';
for i:=0 to c_len-1 do
s := s+ format('%x/',[ord(result)]);
//caption := s;
s2 := '';
for i:=0 to d_len-1 do
s2 := s2+ format('%x/',[ord(data)]);
ShowMessage('golay_code:'+s+#13+'golay_decode:'+s2);
freelibrary(h);
end;
注册表,举个例子:
uses Registry;
procedure TMainForm.FormCreate(Sender: TObject);
var myreg : treginifile;
dbname,vodkey:string;
c:array[0..MAX_PATH]of char;
begin
//得到windows目录
GetWindowsDirectory(c,sizeof(c));
WinDir:=strpas(c);
//得到 程序所在目录
MyDir:= ExtractFilePath(ParamStr(0));
myreg := treginifile.create;
myreg.rootkey := HKEY_LOCAL_MACHINE;
vodkey:='Software/VOD';
DataBase1.Connected := false;
if not myreg.KeyExists(vodkey) then
begin
OpenDlg1.Title := '请选择数据库文件';
if OpenDlg1.Execute then DBname:=OpenDlg1.FileName; //选择数据库文件
if trim(DBname)='' then close;
myreg.WriteString('Software/VOD','DBname',DBname);
DataBase1.DatabaseName := DBname;
end
else
begin
DBname:= myreg.readString(vodkey,'DBname','invalid');
if DBname<>'invalid' then DataBase1.DatabaseName := DBname;
end;
DataBase1.Connected := true;
end;