我想从 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.
发布评论
评论(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.