Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic library Linking at execution

Tags:

c++

winapi

why did it fail to load the library at link at compilation time? i don't care about freeing the library yet it just won't work.

#include <windows.h>

    int main()
    {
        LoadLibrary("winmm.lib");
        timeGetTime();
    }
like image 764
Carl_1789 Avatar asked Feb 19 '26 22:02

Carl_1789


2 Answers

.lib is not a dynamically linked library (DLL), and cannot be loaded at runtime. You need to load the .dll, or link the .lib at link time (at which point you don't use LoadLibrary).

like image 154
Yann Ramin Avatar answered Feb 21 '26 12:02

Yann Ramin


Try this code. It should solve your problem.

#include <windows.h>

#pragma comment(lib, "winmm.lib")

int main()
{
    DWORD time = timeGetTime();
}
like image 27
Jujjuru Avatar answered Feb 21 '26 10:02

Jujjuru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!