Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
Hello!
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 21:25pm
Comments
Sergey Alexandrovich Kryukov at 20-Mar-13 2:33am
   
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".
—SA

1 solution

Rate this: bad
good
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:
    
    LIBRARY   BTREE
    EXPORTS
       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:
    typedef UINT (CALLBACK* LPFNDLLFUNC1)(DWORD, UINT);
 
 
    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
          FreeLibrary(hDLL);    
 
          return SOME_ERROR_CODE;
       }
       else
       {
          // call the function
          uReturnVal = lpfnDllFunc1(dwParam1, uParam2);
       }
    }
 
  Permalink  
v3

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 295
1 OriginalGriff 274
2 Shweta N Mishra 216
3 PIEBALDconsult 184
4 CPallini 155
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2014
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