简体   繁体   中英

Loading a *.dll from a *.lib and using this lib in generating an *exe afterwards: Is it possible?

I want to use the functionality of a 3rd party dll into a lib I create. Something like this:

m_hLib = LoadLibrary(L"Bla.dll"); 

and the using this with:

void* fnBla = ::GetProcAddress(m_hLib , "MethodFromBla");  

to use some stuff from the respective method.

Now my question would be: could I build the lib like this and then use its functions from an exe?

What you're doing is dynamic (or runtime) linking, ie you explicitly load the .dll and resolve the functions via GetProcAddress . If you're doing this then you don't need a .lib file.

A .lib file is only necessary if you want to statically link against the .dll at compile time. The linker takes the .lib file and resolves the references in your program against the functions information in the .lib. Therefore, if you don't plan to link to the .dll at compile time you won't need a .lib. You just need to make sure that the .dll (Bla.dll in your case) it released alongside your application.

No Problems at all . exe gets statically linked to the lib file . That means lib code becomes part of exe code . Now the exe code is loading the dll dynamically :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM