Click here to Skip to main content
13,047,567 members (58,892 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I write my own dll in MFC and want to call the functions of dll in my MFC dialogue based application.There are multiple functions in DLL which are return Handle,int etc. and I would like to call that functions on different events happened on dialogue application.
so my question is how to declare function pointer of that functions globally and call that function with respect to that event?
Please give solution!!!
Posted 19-Mar-13 20:25pm
Not clear what's the problem. Just do it by definition; if in doubt, write a code for simplest sample in just two files, test it, and, if there are problems, show this sample, using "Improve question".

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:
   Insert   @1
   Delete   @2
   Member   @3
   Min   @4

- 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:
    HINSTANCE hDLL;               // Handle to DLL
    LPFNDLLFUNC1 lpfnDllFunc1;    // Function pointer
    DWORD dwParam1;
    UINT  uParam2, uReturnVal;
    hDLL = LoadLibrary("MyDLL");
    if (hDLL != NULL)
       lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, "DLLFunc1");
       if (!lpfnDllFunc1)
          // handle the error
          return SOME_ERROR_CODE;
          // call the function
          uReturnVal = lpfnDllFunc1(dwParam1, uParam2);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100