在 C++ 中运行时加载函数
我有以下问题:
我的程序应该在运行时决定是否加载函数(在本例中为 GetExtendedTcpTable()),因为该方法在 Windows 2000 中不可用!? (仅在Windows 2000下无法启动该软件)
谢谢您的帮助!
问候莱昂22
I have following problem:
My program should decide at runtime to load an function (in this case GetExtendedTcpTable()) or not, because the method is not available in Windows 2000!? (can't start the software only in Windows 2000)
Thank you for your help!
greets leon22
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有完全明确您的问题,但我想您想根据操作系统版本动态加载该函数。
要确定操作系统版本,您可以使用
GetVersionEx
。要动态加载函数,首先使用LoadLibrary
检索其DLL 的模块句柄,然后使用GetProcAddress
检索指向该函数的函数指针。您需要将该函数指针转换为正确的原型。You didn't quite specify your question, but I suppose that you want to load the function dynamically based on the OS version.
To determine the OS version, you can use
GetVersionEx
. To load a function dynamically, first useLoadLibrary
to retrieve the module handle of its DLL, and then useGetProcAddress
to retrieve a function pointer to the function. You will need to cast that function pointer to the correct prototype.如果该函数在特定平台上不可用,您需要在编译时确定是否在运行时加载它。在构建的配置过程中,您可以确定该函数是否可用并进行适当的编译。
If the function is not available on a particular platform, you want to determine at compile time whether or not to load it not at runtime. During the configury of the build, you determine if the function is available and compile appropriately.