停止在 DLL 中寻找运行时的入口点
我有一个在 Windows 2003、Windows 2008 和 Windows Small Business Server 上运行的应用程序。
我有一个用于重新启动系统的 Windows 调用。下面提到的所有调用都来自 advapi32.dll
InitiateSystemshutdown - 这在 Windows 2003 和 Windows 2008 中很好,但由于某种原因在 Windows aurora InitiateShutdown 中不起作用
- 因为上面的调用是在 windows aurora 中不起作用,我们使用了此调用,此调用支持的最低操作系统是 windows 2008
现在,我的应用程序无法在 windows 2003 中运行,因为Windows 2003 上的 advapi32.dll 中不存在 InitiateShutDown
我在 advapi32.dll 中找不到 Initiateshutdown 的过程入口点
我已经设置了一个条件,以便根据 Windows 版本调用正确的函数调用。
有没有办法在应用程序启动时停止寻找 dll 中的入口点。条件将确保调用正确的函数调用?
或者
我应该问微软为什么旧的调用 InitiateSystemshutdown 不能正常工作?
I have an application which runs on windows 2003, window 2008 and windows small business server.
There is a windows call that I make to reboot the system.All the calls mentioned below come from advapi32.dll
InitiateSystemshutdown - This is fine in windows 2003 and windows 2008 but for some reason not working in Windows aurora
InitiateShutdown - since the above call is not working in windows aurora we used this call and minimum supported OS for this call is windows 2008
Now my application fails to run in windows 2003 since the InitiateShutDown is not present in the advapi32.dll on Windows 2003
I get a failed to find procedure entry point for Initiateshutdown in advapi32.dll
I have already put a condition also so that the proper function calls are called with respect to the windows version.
Is there way to stop looking for the entry point in the dll when the application launches.The condition will make sure that the proper function call are called?
OR
I should be asking Microsoft why the old call InitiateSystemshutdown is not working properly ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用 GetProcAddress 并为早期版本的 Windows 设置预处理器变量。请参阅 http://msdn.microsoft.com/en -us/library/aa383745(VS.85).aspx#setting_winver_or__win32_winnt
基本上,你应该:
将 WINVER 设置为您必须支持的最早的 Windows 版本,这样您就不会意外地使用更新的版本。
某些 API 调用和定义在您的代码中将不再起作用(例如您的情况下的 InitiateShutdown),因为它们不包含在头文件中。对于这些,您必须动态地使用它们。通常,您使用 GetProcAddress API 并使用“typedef”来定义函数的签名(因为它不再包含在您要包含的头文件中)。示例如下: http://msdn.microsoft.com /en-us/library/ms683212(VS.85).aspx。在您的情况下,您将使用 InitiateShutdown API 而不是给定的 GetNativeSystemInfo。如果对 GetProcAddress 的调用失败,那么您可以假设该版本的 Windows 不支持该 API。
You have to use GetProcAddress and set your preprocessor variables for the earlier version of Windows. See http://msdn.microsoft.com/en-us/library/aa383745(VS.85).aspx#setting_winver_or__win32_winnt
Basically, you should:
Set WINVER to the earliest version of Windows you must support so you don't accidentally use something newer.
Some API calls and definitions won't work anymore (like InitiateShutdown in your case) in your code, because they aren't included by header files. For these, you must use them dynamically. Typically you use the GetProcAddress API and use a "typedef" to define the function's signature (since it isn't in the header files you're including anymore). An example is here: http://msdn.microsoft.com/en-us/library/ms683212(VS.85).aspx. In your case you would use the InitiateShutdown API instead of the given GetNativeSystemInfo. If the call to GetProcAddress fails then you can assume that the API is not supported on that version of Windows.
不要在代码中显式调用该函数(这样,如果无法从预期的 DLL 加载该函数,您的应用程序将无法加载),而是通过 LoadLibrary 和 GetProcAddress 隐式调用它。
对 advapi32.dll 执行“LoadLibrary”。然后调用 GetProcAddress 进行“InitiateShutdown”。如果该函数不存在,则优雅地失败,否则将其转换为适当的函数指针并
调用它。
Rather that explicitly calling that function in your code (such that your app will fail to load if the function can't be loaded from the expected DLL), call it implicitly via LoadLibrary and GetProcAddress.
Do a "LoadLibrary" on advapi32.dll. And then call GetProcAddress for "InitiateShutdown". Fail gracefully if the function doesn't exist, otherwise cast it to an appropriate function pointer and
invoke it.