Appu82

call_dll_on_the_fly.c

Aug 9th, 2020 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.86 KB | None | 0 0
  1. #include <windows.h>
  2. #include <errno.h>
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. // #define MAXMODULE 50 /* this is not mandatory */
  8.  
  9. typedef int (WINAPI*c_my_func)(); // typedef void (WINAPI*c_my_func2)(); etc. etc. etc.
  10.  
  11. c_my_func func_multi01_dll;
  12. // c_my_func another_function(); /* another function of your choice, you can add more fn. */
  13.  
  14. int main() {
  15.  int returned_value;
  16.        HINSTANCE h_my_Lib_or_nythng=LoadLibrary("easy_dll.dll");
  17.                         /*You can use relative paths like: "../../CBDYNA.DLL" or,
  18.                         absolute path like: "D:/Code_Blocks/linking/CBDYNA.DLL" but
  19.                         be sure to use normal-SLASH not back-slash. */
  20.  
  21.        if(h_my_Lib_or_nythng==NULL) {
  22.  
  23.             printf("Unable to load library!\n");
  24.             getchar();
  25.             return 0;
  26.        }
  27. //--------------------- these lines are not mandatory -----------------//
  28.        // char mod[MAXMODULE];
  29.  
  30.        // GetModuleFileName((HMODULE)h_my_Lib_or_nythng, (LPTSTR)mod, MAXMODULE);
  31.        // printf("Library loaded: \n");
  32. //-------------------- ******* -----------------------//
  33.  
  34.        func_multi01_dll=(c_my_func)GetProcAddress((HMODULE)h_my_Lib_or_nythng, "func_multi01_dll");
  35.    //  another_function=(c_my_func)GetProcAddress((HMODULE)h_my_Lib_or_nythng, "dog"); /* rule for writing other functions. */
  36.  
  37.        if((func_multi01_dll==NULL)) { /* if((cat==NULL) || (dog==NULL)) {} // connect using "OR*. */
  38.  
  39.             printf("Unable to load function(s).");
  40.             FreeLibrary((HMODULE)h_my_Lib_or_nythng);
  41.             return 0;
  42.        }
  43.  
  44.        returned_value=func_multi01_dll();
  45.     // another_function(); /* write other functions.*/
  46.  
  47.        FreeLibrary((HMODULE)h_my_Lib_or_nythng);
  48.  
  49.        printf("returned value from dll=%d\n",returned_value);
  50.        printf("\n");
  51.        system("PAUSE");
  52.        return 0;
  53.  }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment