根据外部函数是否存在来声明它们
我想从 kernel32.dll 库中声明一个外部函数,其名称为 GetTickCount64。 据我所知,它仅在 Vista 和更高版本的 Windows 版本中定义。 这意味着当我按如下方式定义函数时:
function GetTickCount64: int64; external kernel32 name 'GetTickCount64';
由于应用程序启动时生成错误,我肯定无法在以前版本的 Windows 上运行我的应用程序。
这个问题有解决方法吗? 假设我不想在该函数不存在时包含该函数,然后在我的代码中使用一些替代函数。 怎么做? 是否有任何编译器指令有帮助? 我想这个定义必须被这样的指令包围,而且我还必须在使用 GetTickCount64 函数的地方使用一些指令,对吧?
我们将不胜感激您的帮助。 提前致谢。
马吕斯。
I would like to declare an external function from the kernel32.dll library whose name is GetTickCount64. As far as I know, it is defined only in Vista and in later Windows versions. This means that when I define the function as follows:
function GetTickCount64: int64; external kernel32 name 'GetTickCount64';
I will certainly not be able to run my application on previous versions of Windows because of error generated on application startup.
Is there a workaround to that problem? Let's say I would like not to include that function when it does not exist and then use some substitute function in my code. How to do that? Are there any compiler directives that would help?
I gues the definition would have to be surrounded by such directive and I would also have to use some directives wherever I use the GetTickCount64 founction, right?
Your help will be appreciated. Thanks in advance.
Mariusz.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
声明该类型的函数指针,然后在运行时使用
LoadLibrary
或GetModuleHandle
和GetProcAddress
。 您可以在 Delphi 源代码中找到该技术的几个示例; 查看TlHelp32.pas,它加载ToolHelp 库< /a>,这在旧版本的 Windows NT 上不可用。Declare a function pointer of that type, and then load the function at run time with
LoadLibrary
orGetModuleHandle
andGetProcAddress
. You can find several examples of the technique in the Delphi source code; look at TlHelp32.pas, which loads the ToolHelp library, which isn't available on older versions of Windows NT.