CygnusX1
CygnusX1

Reputation: 21818

Cannot find cosf in msvcr100.dll using GetProcAddress

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?

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!

Upvotes: 0

Views: 744

Answers (1)

Hans Passant
Hans Passant

Reputation: 942109

From the <math.h> header file:

inline float cosf(_In_ float _X)
        {return ((float)cos((double)_X)); }

Or in other words, it is an inline function that actually uses cos(). And thus isn't exported from the DLL.

Upvotes: 1

Related Questions