Hi, 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();
}
Hi, 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();
}
.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).
From your comment above, it's clear that the problem is that timeGetTime() requrires the winmm module at compile time, which means you have to link with winmm.lib. You cannot call the function directly by its name if you want to use run-time linking; you have to get its function pointer out of the DLL.
If you truly want to load the DLL at run time, you must use GetProcAddress. A full set of example code for using LoadLibrary properly is found on this MSDN page.
Try this code. It should solve your problem.
#include <windows.h>
#pragma comment(lib, "winmm.lib")
int main()
{
DWORD time = timeGetTime();
}
You are trying to load a .lib file (linker library information) using the LoadLibrary function, which is designed to load dynamic-link libraries - that is plain wrong. .lib files are linked in the executable at link time, whereas the .dll files are loaded at runtime, either via explicit loading using LoadLibrary or by feeding the linker a .lib file that references a .dll file.