Advertisement
dllbridge

dllBridge.h

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