我想在应用程序中调用一DLL,但是我不想在代码中声明,可以通过文本文件配置
来调用DLL,请问怎么实现,最好给我一代码实例,谢谢大家
来调用DLL,请问怎么实现,最好给我一代码实例,谢谢大家
解决方案 »
- 问两个很弱的问题
- 如何在delphi中实现矩阵的逆运算,转置,以及矩阵的乘法和加法.万分感激!!!
- 求助:当我单击 button1 ,希望提示我是否真的运行下面的程序,如果我选择 是,则运行,选择否,则退出,谢谢!
- 用DELPHI如何在XP下屏蔽系统热键?
- 如何使用Tquery+DBGrid访问Access数据库?这样可以使用相对路径吗?在线等待,谢谢
- 救命!
- 打开应为空白的文本柜为什么老显示上次的内容
- 有点难度,如何在OUTLOOK中建立工作?
- 在DBGrid中允许编辑修改数据,但不能增加和删除,如何做?
- 请教
- 有没有朗读中文的控件或是有关这方面的源代码也行!
- delphi 访问unix informix 遇到的一个大BUG
(*********************************************************************
PComm.pas
-- PComm Lib unit for Delphi (32 bit version).
**********************************************************************)unit PComm;interfaceconst
{ baud rate setting }
B50 = $0;
B75 = $1;
B110 = $2;
B134 = $3;
B150 = $4;
B300 = $5;
B600 = $6;
B1200 = $7;
B1800 = $8;
B2400 = $9;
B4800 = $A;
B7200 = $B;
B9600 = $C;
B19200 = $D;
B38400 = $E;
B57600 = $F;
B115200 = $10;
B230400 = $11;
B460800 = $12;
B921600 = $13; { data bit }
BIT_5 = $0;
BIT_6 = $1;
BIT_7 = $2;
BIT_8 = $3; { stop bit }
STOP_1 = $0;
STOP_2 = $4; { parity }
P_EVEN = $18;
P_ODD = $8;
P_SPC = $38;
P_MRK = $28;
P_NONE = $0; { modem control setting }
C_DTR = $1;
C_RTS = $2; { modem line status }
S_CTS = $1;
S_DSR = $2;
S_RI = $4;
S_CD = $8; { error code }
SIO_OK = 0;
SIO_BADPORT = -1; { No such port or port not opened }
SIO_OUTCONTROL = -2; { Can't control board }
SIO_NODATA = -4; { No data to read or no buffer to write }
SIO_OPENFAIL = -5; { No such port or port has opened }
SIO_RTS_BY_HW = -6; { Can't set because H/W flowctrl }
SIO_BADPARM = -7; { Bad parameter }
SIO_WIN32FAIL = -8; (* Call win32 function fail, please call }
GetLastError to get the error code *)
SIO_BOARDNOTSUPPORT = -9; { Board does not support this function}
SIO_FAIL = -10; { PComm function run result fail }
SIO_ABORT_WRITE = -11; { Write has blocked, and user abort write }
SIO_WRITETIMEOUT = -12; { Write timeout has happened } { file transfer error code }
SIOFT_OK = 0;
SIOFT_BADPORT = -1; { No such port or port not open }
SIOFT_TIMEOUT = -2; { Protocol timeout }
SIOFT_ABORT = -3; { User key abort }
SIOFT_FUNC = -4; { Func return abort }
SIOFT_FOPEN = -5; { Can not open files }
SIOFT_CANABORT = -6; { Ymodem CAN signal abort }
SIOFT_PROTOCOL = -7; { Protocol checking error abort }
SIOFT_SKIP = -8; { Zmodem remote skip this send file }
SIOFT_LACKRBUF = -9; { Zmodem Recv-Buff size must >= 2K bytes }
SIOFT_WIN32FAIL = -10; (* OS fail }
GetLastError to get the error code *)
SIOFT_BOARDNOTSUPPORT = -11; { Board does not support this function}type IrqProc = procedure(port: Longint);stdcall;
CallBackProc = function(len: Longint; rlen: Longint; buf: PChar; flen: Longint): Longint;stdcall;{Import routine from PComm.dll}
function sio_open(port: Longint): Longint; stdcall;
function sio_close(port: Longint): Longint; stdcall;
function sio_ioctl(port, baud, mode: Longint): Longint; stdcall;
function sio_flowctrl(port, mode: Longint): Longint; stdcall;
function sio_flush(port, func: Longint): Longint; stdcall;
function sio_DTR(port, mode: Longint): Longint; stdcall;
function sio_RTS(port, mode: Longint): Longint; stdcall;
function sio_lctrl(port, mode: Longint): Longint; stdcall;
function sio_baud(port, speed: Longint): Longint; stdcall;
function sio_getch(port: Longint): Longint; stdcall;
function sio_read(port: Longint; buf: PChar; len: Longint): Longint; stdcall;
function sio_linput(port: Longint; buf:PChar; len: Longint; term:Longint): Longint; stdcall;
function sio_putch(port, term: Longint): Longint; stdcall;
function sio_putb(port: Longint; buf:PChar; len: Longint): Longint; stdcall;
function sio_write(port: Longint; buf:PChar; len: Longint): Longint; stdcall;
function sio_putb_x(port: Longint; buf:PChar; len: Longint; tick:Longint): Longint; stdcall;
function sio_putb_x_ex(port: Longint; buf:PChar; len: Longint; tms:Longint): Longint; stdcall;
function sio_lstatus(port: Longint): Longint; stdcall;
function sio_iqueue(port: Longint): Longint; stdcall;
function sio_oqueue(port: Longint): Longint; stdcall;
function sio_Tx_hold(port: Longint): Longint; stdcall;
function sio_getbaud(port: Longint): Longint; stdcall;
function sio_getmode(port: Longint): Longint; stdcall;
function sio_getflow(port: Longint): Longint; stdcall;
function sio_data_status(port: Longint): Longint; stdcall;
function sio_term_irq(port: Longint; func: IrqProc; code: Byte): Longint; stdcall;
function sio_cnt_irq(port: Longint; func: IrqProc; count: Longint): Longint; stdcall;
function sio_modem_irq(port: Longint; func: IrqProc): Longint; stdcall;
function sio_break_irq(port: Longint; func: IrqProc): Longint; stdcall;
function sio_Tx_empty_irq(port: Longint; func: IrqProc): Longint; stdcall;
function sio_break(port, time: Longint): Longint; stdcall;
function sio_break_ex(port, time: Longint): Longint; stdcall;
function sio_view(port: Longint; buf: PChar; len: Longint): Longint; stdcall;
function sio_TxLowWater(port, size: Longint): Longint; stdcall;
function sio_AbortWrite(port: Longint): Longint; stdcall;
function sio_AbortRead(port: Longint): Longint; stdcall;
function sio_SetWriteTimeouts(port, timeouts: Longint): Longint; stdcall;
function sio_GetWriteTimeouts(port: Longint; var TotalTimeouts:Longint): Longint; stdcall;
function sio_SetReadTimeouts(port, TotalTimeouts, IntervalTimeouts: Longint): Longint; stdcall;
function sio_GetReadTimeouts(port: Longint; var TotalTimeouts, IntervalTimeouts: Longint): Longint; stdcall;
function sio_ActXon(port: Longint): Longint; stdcall;
function sio_ActXoff(port: Longint): Longint; stdcall;
function sio_FtASCIITx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtASCIIRx(port:Longint; fname:PChar; func:CallBackProc; key:Longint; sec:Longint): Longint; stdcall;
function sio_FtXmodemCheckSumTx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtXmodemCheckSumRx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtXmodemCRCTx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtXmodemCRCRx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtXmodem1KCRCTx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtXmodem1KCRCRx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtYmodemTx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtYmodemRx(port:Longint; var fname:PChar;fno:LongInt;func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtZmodemTx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtZmodemRx(port:Longint; var fname:PChar;fno:LongInt;func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtKermitTx(port:Longint; fname:PChar; func:CallBackProc; key:Longint): Longint; stdcall;
function sio_FtKermitRx(port:Longint; var fname:PChar;fno:LongInt;func:CallBackProc; key:Longint): Longint; stdcall;
function sio_open; external 'PComm.dll';
function sio_close; external 'PComm.dll';
function sio_ioctl; external 'PComm.dll';
function sio_flowctrl; external 'PComm.dll';
function sio_flush; external 'PComm.dll';
function sio_DTR; external 'PComm.dll';
function sio_RTS; external 'PComm.dll';
function sio_lctrl; external 'PComm.dll';
function sio_baud; external 'PComm.dll';
function sio_getch; external 'PComm.dll';
function sio_read; external 'PComm.dll';
function sio_linput; external 'PComm.dll';
function sio_putch; external 'PComm.dll';
function sio_putb; external 'PComm.dll';
function sio_write; external 'PComm.dll';
function sio_putb_x; external 'PComm.dll';
function sio_putb_x_ex; external 'PComm.dll';
function sio_lstatus; external 'PComm.dll';
function sio_iqueue; external 'PComm.dll';
function sio_oqueue; external 'PComm.dll';
function sio_Tx_hold; external 'PComm.dll';
function sio_getbaud; external 'PComm.dll';
function sio_getmode; external 'PComm.dll';
function sio_getflow; external 'PComm.dll';
function sio_data_status; external 'PComm.dll';
function sio_term_irq; external 'PComm.dll';
function sio_cnt_irq; external 'PComm.dll';
function sio_modem_irq; external 'PComm.dll';
function sio_break_irq; external 'PComm.dll';
function sio_Tx_empty_irq; external 'PComm.dll';
function sio_break; external 'PComm.dll';
function sio_break_ex; external 'PComm.dll';
function sio_view; external 'PComm.dll';
function sio_TxLowWater; external 'PComm.dll';
function sio_AbortWrite; external 'PComm.dll';
function sio_AbortRead; external 'PComm.dll';
function sio_SetWriteTimeouts; external 'PComm.dll';
function sio_GetWriteTimeouts; external 'PComm.dll';
function sio_SetReadTimeouts; external 'PComm.dll';
function sio_GetReadTimeouts; external 'PComm.dll';
function sio_ActXon; external 'PComm.dll';
function sio_ActXoff; external 'PComm.dll';
function sio_FtASCIITx; external 'PComm.dll';
function sio_FtASCIIRx; external 'PComm.dll';
function sio_FtXmodemCheckSumTx; external 'PComm.dll';
function sio_FtXmodemCheckSumRx; external 'PComm.dll';
function sio_FtXmodemCRCTx; external 'PComm.dll';
function sio_FtXmodemCRCRx; external 'PComm.dll';
function sio_FtXmodem1KCRCTx; external 'PComm.dll';
function sio_FtXmodem1KCRCRx; external 'PComm.dll';
function sio_FtYmodemTx; external 'PComm.dll';
function sio_FtYmodemRx; external 'PComm.dll';
function sio_FtZmodemTx; external 'PComm.dll';
function sio_FtZmodemRx; external 'PComm.dll';
function sio_FtKermitTx; external 'PComm.dll';
function sio_FtKermitRx; external 'PComm.dll';end.
以后在其他单元里,只要包含了pcomm,就可以直接使用里面的函数了
我的想法是做一个主程序框架,之后每一个功能做成一个动态链接库
主程序与DLL分离,在运行期可以通过配文本文件置来调用DLL
type
TFunc = function(var aa: integer): integer;
var
h: THandle;
func : TFunc;
begin
h := LoadLibrary(‘adf');
func := GetProcessName('adffd'); //你的dll的函数
TFunc(func(12)); //执行
freeLibrary(h);
end;
各位,什么原因,还有没有别的好办法
因为以前我经历过一个项目,就是以DLL形式开发出一个功能模块,之后在一文本文件中
配置一下记录动态链接库的基本信息,之后主程序执行时会自动调用动态链接库,而不需要
修改主程序,但当时我刚刚入此门,也不没能懂,现在我要用到此方法,各位多多帮忙,谢谢大家了。
DLL的文件名、接口名及参数
GetProcAddress//得到函数地址,返回指针
GetProcAddress(dll句柄, '函数名字符串')
把dll文件名字符串、函数名字符串改为从文本文件或者数据库读取就可以了吧
type
TGetVersion = function(): PChar; stdcall;
var
GetVersion: TGetVersion;
begin
FDllHandle := LoadLibrary(PChar(sFilename)); if FDllHandle = 0 then
begin
msg := 'DLL没有成功装入!' + #13#10 + sFilename;
MessageBox(Application.Handle,PChar(msg), '系统提示', MB_ICONINFORMATION);
exit;
end; try
//获取DLL文件信息
@GetVersion := GetProcAddress(FDllHandle, 'GetVersion');
if @GetVersion <> nil then Result := GetVersion();
except
msg := '定位应用入口函数失败!' + #13#10 + sFilename;
MessageBox(Application.Handle,PChar(msg),'系统提示',MB_ICONINFORMATION);
Exit;
end;
end;
var
getPro:TGetPro @getPro:=GetProcAddress(dll句柄, '函数名字符串')
不过我不懂