Load DLL Library

人盡茶涼 提交于 2019-12-11 01:09:56

问题


Is it possible to load a DLL with C and use its functions?

I am new in C, and I am trying to search some good references on the internet for this; but I can't find any.

Any help would be appreciated!

I am using GNU GCC in Code::Blocks on Windows 7, 64 Bit.


回答1:


HMODULE hModule = LoadLibrary(<dll file name>) followed by GetProcAddress(hModule, <function name>) will do this job using the WinAPI.

An example could be found here.




回答2:


I think you should investigate the LoadLibrary function.

http://msdn.microsoft.com/en-us/library/ms684175.aspx

Loads the specified module into the address space of the calling process. The specified module may cause other modules to be loaded.




回答3:


Building a DLL using MinGW, here are some instructions:

First, you need to mark your functions for export, so they can be used by callers of the DLL. To do this, modify them so they look like (for example)

__declspec( dllexport ) int add2(int num){
   return num + 2;
}

then, assuming your functions are in a file called funcs.c, you can compile them:

gcc -shared -o mylib.dll funcs.c The -shared flag tells gcc to create a DLL.

For a free IDE which will automate all the flags etc. needed to build DLLs, take a look at the excellent Code::Blocks, which works very well with MinGW.

Also, see the article Creating a MinGW DLL for Use with Visual Basic on the MinGW Wiki.



来源:https://stackoverflow.com/questions/13034728/load-dll-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!