如果需要,Delphi是否只能使用.dll?
发布时间:2020-12-15 10:04:55 所属栏目:大数据 来源:网络整理
导读:我已将这两种方法添加到我的Delphi 5应用程序的第一单元中. function Inp(PortAddress: Integer): Integer; stdcall; external 'inpout32.dll' name 'Inp32';procedure Output(PortAddress,Value: Integer); stdcall; external 'inpout32.dll' name 'Out32';
我已将这两种方法添加到我的Delphi 5应用程序的第一单元中.
function Inp(PortAddress: Integer): Integer; stdcall; external 'inpout32.dll' name 'Inp32'; procedure Output(PortAddress,Value: Integer); stdcall; external 'inpout32.dll' name 'Out32'; 但是,除非他们明确需要,否则我不想用软件发布inpout32库.目前程序在执行时说“未找到”,除非它们存在于根或System32中. 用户只有在设置了特定选项时才会调用这些方法,但在使用inpout库之前,不会从.ini文件中收集这些方法. 有没有办法只在某些组件需要时才使用这个库,而不是按照我的方式声明它? 解决方法
在2010年之前的Delphi版本中,您必须使用经典的动态加载.考虑一下从Kernel32.dll调用
Beep 函数的典型(简单)示例(当然,您不应该在实际代码中硬编码路径!):
type TBeepFunc = function(dwFreq: DWORD; dwDuration: DWORD): BOOL; stdcall; procedure TForm4.FormClick(Sender: TObject); var lib: HMODULE; prc: TBeepFunc; begin lib := LoadLibrary('C:WINDOWSSystem32Kernel32.dll'); if lib = 0 then RaiseLastOSError; try @prc := GetProcAddress(lib,'Beep'); if Assigned(prc) then prc(400,2000) else ShowMessage('WTF? No Beep in Kernel32.dll?!'); finally FreeLibrary(lib); end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |