使用 GetProcAddress 无法在 msvcr100.dll 中找到 cosf
我正在学习如何在运行时加载 DLL 文件并从那里调用函数。 首先,我决定选择数学 cosf
函数。经过一番搜索,我了解到所有数学函数都可以在 msvcr100.dll
中找到。这是我编写的代码:
#include <stdio.h>
#include <Windows.h>
FARPROC getEntry(HMODULE &m, const char* name) {
FARPROC p=GetProcAddress(m, name);
if (!p) {
printf("Error: Entry %s not found\n", name);
printf("Error code: %d\n",GetLastError());
exit(1);
} else
printf("Entry %s loaded\n", name);
return p;
}
int main() {
HMODULE msvcr = LoadLibraryA("msvcr100.dll");
if (!msvcr)
printf("File msvcr100.dll not found\n");
else
printf("msvcr100.dll loaded\n");
FARPROC fun = getEntry(msvcr, "cos");
FARPROC fun2 = getEntry(msvcr, "cosf");
FreeLibrary(msvcr);
return 0;
}
如果运行它,我会得到以下输出:
msvcr100.dll loaded
Entry cos loaded
Error: Entry cosf not found
Error code: 127
为什么?
- 错误代码127代表
ERROR_PROC_NOT_FOUND
——找不到指定的过程。 - 根据 Dependency Walker 的说法,MSVCR100.DLL 中有一个
cosf
函数。序号 1349,入口点 0xC2750。 - 函数名称似乎没有被破坏。
- “cos”和“cosf”均列在运行时库函数参考中: http://msdn.microsoft.com/en-us/library/ydcbat90.aspx
我缺少什么? 如果我应该为 cosf
使用不同的 dll - 是哪一个? cos
接受双精度数,我需要一个接受浮点数的函数。
谢谢你!
I am learning myself to load DLL files at run time and call functions from there.
For a start, I decided to pick mathematical cosf
function. After some searching I learned that all mathematical functions can be found in msvcr100.dll
. So here is code that I have written:
#include <stdio.h>
#include <Windows.h>
FARPROC getEntry(HMODULE &m, const char* name) {
FARPROC p=GetProcAddress(m, name);
if (!p) {
printf("Error: Entry %s not found\n", name);
printf("Error code: %d\n",GetLastError());
exit(1);
} else
printf("Entry %s loaded\n", name);
return p;
}
int main() {
HMODULE msvcr = LoadLibraryA("msvcr100.dll");
if (!msvcr)
printf("File msvcr100.dll not found\n");
else
printf("msvcr100.dll loaded\n");
FARPROC fun = getEntry(msvcr, "cos");
FARPROC fun2 = getEntry(msvcr, "cosf");
FreeLibrary(msvcr);
return 0;
}
If I run it, I get the following output:
msvcr100.dll loaded
Entry cos loaded
Error: Entry cosf not found
Error code: 127
Why?
- Error code 127 stand for
ERROR_PROC_NOT_FOUND
-- The specified procedure could not be found. - According to Dependency Walker, there is a
cosf
function inside MSVCR100.DLL. Ordinal number 1349, Entry Point 0xC2750. - The function name does not seem to be mangled.
- Both 'cos' and 'cosf' are listed in the run-time library function reference: http://msdn.microsoft.com/en-us/library/ydcbat90.aspx
What am I missing?
If I should use a different dll for cosf
-- which one is it?cos
takes doubles, I need a function which takes floats.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
头文件来看:或者换句话说,它是一个实际使用 cos() 的内联函数。因此不会从 DLL 中导出。
From the
<math.h>
header file:Or in other words, it is an inline function that actually uses cos(). And thus isn't exported from the DLL.