Take a look at this article with example and explanation: DYNAMIC LINK LIBRARY - DLL
Basically you can import public symbols into an application or export functions from a DLL using two methods:
- Use a module definition (.DEF) file when building the DLL.
A minimal .DEF file must contain the following module-definition statements:
The first statement in the file must be the LIBRARY statement. This statement identifies the .DEF file as belonging to a DLL. The LIBRARY statement is followed by the name of the DLL. The linker places this name in the DLL's import library.
The EXPORTS statement lists the names and, optionally, the ordinal values of the functions exported by the DLL. You assign the function an ordinal value by following the function's name with an at sign (@) and a number. When you specify ordinal values, they must be in the range 1 through N, where N is the number of functions exported by the DLL.
For example, a DLL that contains the code to implement a binary search tree might look like the following:
- Use the keywords __declspec(dllimport) or __declspec(dllexport) in a function definition in the main application:
__declspec(dllexport) int mydll(LPTSTR lpszMsg)
And here an example how to use explicit linking to load the DLL at run time:
typedef UINT (CALLBACK* LPFNDLLFUNC1)(DWORD, UINT);
HINSTANCE hDLL; LPFNDLLFUNC1 lpfnDllFunc1; DWORD dwParam1;
UINT uParam2, uReturnVal;
hDLL = LoadLibrary("MyDLL");
if (hDLL != NULL)
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, "DLLFunc1");
uReturnVal = lpfnDllFunc1(dwParam1, uParam2);