Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 0) extern "C" __declspec(dllexport)
- - - - - - - - - - - - - - - - - -
- 1) int (*_rr)();
- 2) HMODULE hDll = 0;
- 3) hDll = LoadLibrary("dll/for.dll");
- 4) _rr = (int(*)())GetProcAddress(hDll, "_rr");
- 5) FreeLibrary(hDll);
- */
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // File dllmain.cpp
- #include <windows.h>
- // !!! Обязательно инициализируйте в этой области все массивы и переменные !!!
- //******************************* For Microsoft compiler ****************
- #ifdef _MSC_VER //*****************************************************************************
- #pragma data_seg("SSComp") // совместный доступ к переменным dll
- int _n = 123,
- arr[22] = {0};
- #pragma data_seg()
- #pragma comment(linker,"/section:SSComp,rws")
- #endif
- #ifdef __GNUC__ //******************************* For GCC compiler ******************
- // !!! Обязательно инициализируйте в этой области все массивы и переменные !!!
- __declspec (dllexport) int _n __attribute__((section (".shared"), shared))
- = 123;
- __declspec (dllexport) int arr[22] __attribute__((section (".shared"), shared))
- = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- #endif
- BOOL APIENTRY DllMain (HINSTANCE hInst, // Library instance handle.
- DWORD reason, // Reason this function is being called.
- LPVOID reserved) // Not used.
- {
- switch(reason)
- {
- case DLL_PROCESS_ATTACH:
- break;
- case DLL_PROCESS_DETACH:
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- }
- return TRUE; // Returns TRUE on success, FALSE on failure
- }
- ////////////////////////////////
- extern "C" __declspec(dllexport)
- /////////////////////////////////////////////////////
- int _rr() //
- {
- return 1142;
- }
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // File main.cpp
- #include <windows.h>
- #include <stdio.h>
- HMODULE hDll = 0;
- int (*_rr)();
- ////////////////////////////////////////////////////
- int main() //
- {
- hDll = LoadLibrary("dll/for.dll");
- if(hDll == 0)
- {
- printf("Error LoadLibrary\n");
- return 0;
- }
- _rr = (int(*)())GetProcAddress(hDll, "_rr");
- if(_rr == 0)
- {
- printf("Error Get Proc\n");
- FreeLibrary(hDll);
- return 0;
- }
- printf("_rr() = %d", _rr() );
- FreeLibrary(hDll); Sleep(2000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement