Saturday, May 22, 2010

How do I link a .DLL into my C program on windows.?

I am using microsoft visual studio platform to run my c code.I am calling some functions which are available in a DLL.


How do i link that DLL into my C code so that i can use functions from that DLL.

How do I link a .DLL into my C program on windows.?
If you have the corresponding .LIB file for your DLL, just link that file with your project and declare functions in your C/C++ code using dllimport (or include header file if it comes with the library):





http://msdn2.microsoft.com/en-us/library...





If you don't have .LIB file, you do it manually using LoadLibrary() / GetProcAddress():





typedef VOID (*MYPROC)(LPTSTR);


...


MYPROC pFunction;


HINSTNCE hDLL = LoadLibrary("file.dll");


...


pFunction = (MYPROC) GetProcAddress(hDLL, "MyFunctionFromDLL");





The following MSDN article will help:


http://msdn2.microsoft.com/en-us/library...


No comments:

Post a Comment