Advertisement
dllbridge

extract for dll

Jul 3rd, 2023 (edited)
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.36 KB | None | 0 0
  1. /*
  2. 0) extern "C" __declspec(dllexport)
  3.    - - - - - - - - - - - - - - - - -
  4. 1) int (*_rr)();
  5. 2) HMODULE  hDll = 0;
  6. 3) hDll = LoadLibrary("dll/for.dll");
  7. 4) _rr = (int(*)())GetProcAddress(hDll, "_rr");
  8. 5) FreeLibrary(hDll);
  9. */
  10.  
  11.  
  12.  
  13.  
  14. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  15. // File dllmain.cpp
  16.  
  17. #include <windows.h>
  18.  
  19.  
  20. //              !!!   Обязательно инициализируйте в этой области все массивы и переменные   !!!    
  21.                 //*******************************    For Microsoft compiler    ****************  
  22. #ifdef _MSC_VER //*****************************************************************************
  23. #pragma data_seg("SSComp")                                // совместный доступ к переменным dll
  24.            
  25.                          
  26. int        _n  = 123,
  27.  
  28.        arr[22] = {0};
  29.        
  30. #pragma data_seg()
  31. #pragma comment(linker,"/section:SSComp,rws")          
  32. #endif  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. #ifdef __GNUC__ //*******************************     For GCC compiler      ******************  
  47.                 // !!! Обязательно инициализируйте в этой области все массивы и переменные !!!
  48.                                                                                  
  49.  __declspec (dllexport) int        _n              __attribute__((section (".shared"), shared))
  50.                                        = 123;  
  51.                                                                                                        
  52.  __declspec (dllexport) int    arr[22]             __attribute__((section (".shared"), shared))                              
  53.                                        = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};                                                                                                                                                         
  54. #endif
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. BOOL APIENTRY DllMain (HINSTANCE hInst,         // Library instance handle.
  62.                        DWORD    reason,         // Reason this function is being called.
  63.                        LPVOID reserved)         // Not used.
  64. {
  65.     switch(reason)
  66.     {
  67.       case DLL_PROCESS_ATTACH:
  68.                                break;
  69.  
  70.       case DLL_PROCESS_DETACH:
  71.                                break;
  72.  
  73.       case DLL_THREAD_ATTACH:
  74.                                break;
  75.  
  76.       case DLL_THREAD_DETACH:
  77.                                break;
  78.     }
  79.  
  80.  
  81.     return TRUE;                                              // Returns TRUE on success, FALSE on failure
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88. ////////////////////////////////
  89. extern "C" __declspec(dllexport)
  90. /////////////////////////////////////////////////////
  91. int _rr()                                          //  
  92. {
  93.    
  94. return 1142;   
  95. }
  96.  
  97.  
  98.  
  99. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  100. // File main.cpp
  101.  
  102.  
  103.  
  104.  
  105. #include   <windows.h>
  106. #include     <stdio.h>
  107.  
  108.  
  109.  
  110. HMODULE  hDll = 0;
  111.  
  112.  
  113. int (*_rr)();
  114.  
  115.  
  116. ////////////////////////////////////////////////////
  117. int main()                                        //
  118. {
  119.  
  120.  
  121.     hDll = LoadLibrary("dll/for.dll");
  122.    
  123.     if(hDll == 0)
  124.     {
  125.        
  126.        printf("Error LoadLibrary\n");
  127.        return 0;   
  128.     }
  129.  
  130.    _rr = (int(*)())GetProcAddress(hDll, "_rr");
  131.    
  132.     if(_rr == 0)
  133.     {
  134.        
  135.        printf("Error Get Proc\n");
  136.        FreeLibrary(hDll);
  137.        return 0;   
  138.     }
  139.    
  140.     printf("_rr() = %d", _rr() );
  141.  
  142.     FreeLibrary(hDll); Sleep(2000);
  143.    
  144. return 0;
  145. }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement