Advertisement
dllbridge

dllBridge.h

Dec 25th, 2021
1,518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.73 KB | None | 0 0
  1.  
  2.  
  3. ////////////////////////////////////////////////////////////////////////////////////
  4. //                                                                                //
  5. //   dllBridge@gmail.com
  6. //
  7. //   24 Dec 2021  (14:52)
  8. //   18 Sep 2020  (12:14)
  9. //
  10.  
  11.  
  12. #ifdef     _MSC_VER
  13. #define    _CRT_SECURE_NO_WARNINGS
  14. #endif
  15.  
  16. #include    <stdio.h>
  17. #include   <string.h>
  18. #include   <locale.h>                                  //  Здесь живёт setlocale()
  19. #include  <windows.h>
  20.  
  21.  
  22.  
  23.  
  24. HINSTANCE                hDll;
  25.  
  26. char           szPathDLL[111],
  27.               szPathBase[100] = "C:\\dllBridge",                                       //  Default folder                    
  28.                szWLError[201];
  29.  
  30. int             ProgramNumber = 299,                                                         //              
  31.                       nPerson = 214,                                                         //      User number
  32.               (*Transit)[100];
  33.              
  34. //////////////////////////////
  35. int*   (*__getAdrBOSS)(int n);
  36. int    (*__DisConnect)(int n);
  37. int dllBridge(const char *sz);
  38.  
  39.  
  40.  
  41.  
  42.  
  43. #ifdef __cplusplus   // g++  (C++) code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  
  44.  
  45. namespace
  46. {
  47.    struct WLMain
  48.    {
  49.        
  50.        int  res;
  51.        
  52.        ///////////////////////////////////////////////                           Transit[3][17] = 317;
  53.        WLMain()                                     //                   printf("\nres = %d \n", res);
  54.        {
  55.        
  56.               res =    dllBridge(szPathBase);  
  57.            if(res < 1) printf("%s   \n", szWLError);  
  58.            else        printf("The dllBridge.dll was successfully connected.\n");                  
  59.        }
  60.        
  61.        ///////////////////////////////////////////////
  62.       ~WLMain()                                     //  
  63.        {
  64.            if(res) __DisConnect(ProgramNumber);
  65.        }       
  66.    
  67.    } Obj;
  68.    
  69. }  
  70.  
  71. #endif                   // #else        // C   code + + + + + + + + + + + + + + + + +
  72.  
  73.  
  74.  
  75.  
  76.  
  77. ///////////////////////////////////////////////////////////////////////////////////////
  78. int dllBridge(const char *sz)                                                        //
  79. {
  80.    
  81.     if(hDll) FreeLibrary(hDll);                                                      //  To reconnect DLL.
  82.     else     setlocale(LC_ALL, "Rus");                  //  The Cyrillic alphabet to a console application
  83.    
  84.     char   sz1[201];
  85.     strcpy(sz1, sz);      
  86.     strcat(sz1, "\\dllBridge.dll");
  87.    
  88.    
  89.     hDll = LoadLibrary(sz1);                                                         //
  90.    
  91.     int res;
  92.    
  93.     if(hDll == 0)
  94.     {
  95.        res = 0;
  96.        goto L_02;
  97.     }  
  98.                                                            
  99.   __getAdrBOSS = (int*(*)(int))GetProcAddress(hDll,   "__getAdrBOSS");                 
  100.  
  101.     Transit = (int(*)[100])__getAdrBOSS(ProgramNumber);     //   Second_Number);//     
  102.            
  103.     if(     Transit ==  0) { res = -2; goto L_02; }                             //  All connections are busy.
  104.     if((int)Transit == -1) { res = -1; goto L_02; }      //  A program with this number is already connected.
  105.  
  106.   __DisConnect =   (int (*)(int))GetProcAddress(hDll, "__DisConnect");   
  107.  
  108.     strcpy(szPathDLL, sz1);
  109.    
  110.      
  111.     Transit[10][0] = 2;  
  112.        
  113.    
  114.     memcpy(&Transit[10][1], "Console project", 15);  //  ! ! ! //memcpy(&Transit[10][1], szProjectInfo[1], 23);
  115.    
  116.     strcpy(szPathBase, sz);   //  szPathBase
  117.    
  118. return       (int)hDll ;   
  119. L_02: FreeLibrary(hDll);
  120.      
  121.  
  122.     switch(res)
  123.     {
  124.        
  125.         case   0:  strcpy(szWLError, "I can't load the library (dll)");                     break;                                 
  126.         case  -1:  strcpy(szWLError, "A program with this number is already connected.");   break;                     
  127.         case  -2:  strcpy(szWLError, "All connections are busy.");         
  128.                                                            
  129.     }   return res;        
  130. }
  131.  
  132.  
  133.  
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement