home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 December (DVD) / VPR0112A.ISO / OLS / UNDLL108 / undll108.lzh / src.lzh / UNDLL.C < prev    next >
C/C++ Source or Header  |  2000-12-31  |  4KB  |  151 lines

  1. /*
  2.     undll.exe Ver.1.08    Copyright (C) 1999-2001  K.Takata
  3. */
  4.  
  5. #include <windows.h>
  6.  
  7. #define BUFFSIZE (1536 * 1024)            // 1.5MB
  8.  
  9. typedef int (WINAPI *ARC_MAINPROC)(const HWND, LPCSTR, LPSTR, const DWORD);
  10. typedef WORD (WINAPI *ARC_GETVERSION)(VOID);
  11.  
  12.  
  13. HANDLE g_hStdOut;            // handle for standard output
  14.  
  15.  
  16. void myfputs(char *str, HANDLE handle)
  17. {
  18.     DWORD dwWritten;
  19.     WriteFile(handle, str, lstrlen(str), &dwWritten, NULL);
  20. }
  21.  
  22. void usage(void)
  23. {
  24.     char *msg =
  25.         "undll.exe Ver.1.08   Copyright (C) 1999-2001  K.Takata\n";
  26.     
  27.     myfputs(msg, g_hStdOut);
  28. }
  29.  
  30. typedef struct {
  31.     char *ModuleName;
  32.     char *DLLName;
  33.     char *MainProc;
  34. } DLLINFO;
  35.  
  36. DLLINFO dllinfo[] = {
  37.     {"unlha32" , "unlha32" , "Unlha" },
  38.     {"unzip32" , "unzip32" , "UnZip" },
  39.     {"zip32"   , "zip32j"  , "Zip"   },
  40.     {"unarj32" , "unarj32j", "Unarj" },
  41.     {"tar32"   , "tar32"   , "Tar"   },
  42.     {"cab32"   , "cab32"   , "Cab"   },
  43.     {"unrar32" , "unrar32" , "Unrar" },
  44.     {"ish32"   , "ish32"   , "Ish"   },
  45. //    {"ftp32"   , "ftp32"   , "Ftp"   },
  46. //    {"unkanj"  , "unkanj"  , "ccCommand"},
  47.     {"bga32"   , "bga32"   , "Bga"   },
  48.     {"jack32"  , "jack32"  , "Jack"  },
  49.     {"unbel32" , "unbel32" , "Unbel" },
  50.     {"aish32"  , "aish32"  , "Aish"  },
  51.     {"aishmv32", "aishmv32", "Aishmv"},
  52. };
  53.  
  54. #ifndef numberof
  55. #define numberof(arr)    (sizeof(arr) / sizeof(arr[0]))
  56. #endif
  57.  
  58.  
  59. int main(int argc, char *argv[])
  60. {
  61.     char buf[BUFFSIZE];
  62.     int ret, i;
  63.     unsigned char *lpszCommandLine, *fname, *p, *lpszOrgCommandLine;
  64. //    WORD wVer;
  65.     ARC_MAINPROC ArcMainProc;
  66. //    ARC_GETVERSION ArcGetVersion;
  67.     HMODULE hDLL = NULL;
  68.     
  69.     
  70.     // Get handle for standard output
  71.     g_hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  72.     
  73.     
  74.     fname = lpszCommandLine = lpszOrgCommandLine = GetCommandLine();
  75.     
  76.     // Skip past program name (first token in command line)
  77.     
  78.     // Check for and handle quoted program name
  79.     if (*lpszCommandLine == '"') {
  80.         // Scan, and skip over, subsequent characters until another
  81.         // double-quote or a null is encountered
  82.         do {
  83.             lpszCommandLine++;
  84.         } while (*lpszCommandLine && (*lpszCommandLine != '"'));
  85.         
  86.         // If we stopped on a double-quote (usual case), skip over it.
  87.         if (*lpszCommandLine == '"') {
  88.             *lpszCommandLine++ = '\0';
  89.         }
  90.     } else {
  91.         // First token wasn't a quote
  92.         while (*lpszCommandLine > ' ') {
  93.             lpszCommandLine++ ;
  94.         }
  95.     }
  96.     
  97.     // skip past any white space preceeding the second token.
  98.     while (*lpszCommandLine && (*lpszCommandLine <= ' ')) {
  99.         *lpszCommandLine++ = '\0';
  100.     }
  101.     
  102.     if (*lpszCommandLine == '\0') {
  103.         usage();
  104.         return 1;
  105.     }
  106.     
  107. //    GetModuleFileName(NULL, buf, _MAX_PATH /*sizeof(buf)*/);
  108.     
  109.     p = fname + lstrlen(fname);
  110.     if (*(p - 4) == '.') {        // cut ".ext"
  111.         p -= 4;
  112.         *p = '\0';
  113.     }
  114.     for (i = 0; i < numberof(dllinfo); i++) {
  115.         fname =  p - lstrlen(dllinfo[i].ModuleName);
  116.         if (lpszOrgCommandLine < fname) {
  117.             char c = *(fname - 1);
  118.             if (c > ' ' && c != '\\' && c != ':' && c != '\"')
  119.                 continue;
  120.         }
  121.         if (lstrcmpi(fname, dllinfo[i].ModuleName) == 0) {
  122.             hDLL = LoadLibrary(dllinfo[i].DLLName);
  123.             if (hDLL == NULL) {
  124.                 myfputs("Can't load the DLL.\n", g_hStdOut);
  125.                 return 2;
  126.             }
  127.             break;
  128.         }
  129.     }
  130.     
  131.     if (hDLL == NULL) {
  132.         usage();
  133.         return 1;
  134.     }
  135.     
  136.     ArcMainProc = (ARC_MAINPROC) GetProcAddress(hDLL, dllinfo[i].MainProc);
  137. //    wsprintf(buf, "%sGetVersion", dllinfo[i].MainProc);
  138. //    ArcGetVersion = (ARC_GETVERSION) GetProcAddress(hDLL, buf);
  139.     
  140. //    wVer = ArcGetVersion();
  141.     ret = ArcMainProc(NULL, lpszCommandLine, buf, sizeof(buf));
  142.     
  143.     FreeLibrary(hDLL);
  144.     
  145.     buf[sizeof(buf) - 1] = '\0';
  146.     
  147.     myfputs(buf, g_hStdOut);
  148.     
  149.     return ret;
  150. }
  151.