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 >
Wrap
C/C++ Source or Header
|
2000-12-31
|
4KB
|
151 lines
/*
undll.exe Ver.1.08 Copyright (C) 1999-2001 K.Takata
*/
#include <windows.h>
#define BUFFSIZE (1536 * 1024) // 1.5MB
typedef int (WINAPI *ARC_MAINPROC)(const HWND, LPCSTR, LPSTR, const DWORD);
typedef WORD (WINAPI *ARC_GETVERSION)(VOID);
HANDLE g_hStdOut; // handle for standard output
void myfputs(char *str, HANDLE handle)
{
DWORD dwWritten;
WriteFile(handle, str, lstrlen(str), &dwWritten, NULL);
}
void usage(void)
{
char *msg =
"undll.exe Ver.1.08 Copyright (C) 1999-2001 K.Takata\n";
myfputs(msg, g_hStdOut);
}
typedef struct {
char *ModuleName;
char *DLLName;
char *MainProc;
} DLLINFO;
DLLINFO dllinfo[] = {
{"unlha32" , "unlha32" , "Unlha" },
{"unzip32" , "unzip32" , "UnZip" },
{"zip32" , "zip32j" , "Zip" },
{"unarj32" , "unarj32j", "Unarj" },
{"tar32" , "tar32" , "Tar" },
{"cab32" , "cab32" , "Cab" },
{"unrar32" , "unrar32" , "Unrar" },
{"ish32" , "ish32" , "Ish" },
// {"ftp32" , "ftp32" , "Ftp" },
// {"unkanj" , "unkanj" , "ccCommand"},
{"bga32" , "bga32" , "Bga" },
{"jack32" , "jack32" , "Jack" },
{"unbel32" , "unbel32" , "Unbel" },
{"aish32" , "aish32" , "Aish" },
{"aishmv32", "aishmv32", "Aishmv"},
};
#ifndef numberof
#define numberof(arr) (sizeof(arr) / sizeof(arr[0]))
#endif
int main(int argc, char *argv[])
{
char buf[BUFFSIZE];
int ret, i;
unsigned char *lpszCommandLine, *fname, *p, *lpszOrgCommandLine;
// WORD wVer;
ARC_MAINPROC ArcMainProc;
// ARC_GETVERSION ArcGetVersion;
HMODULE hDLL = NULL;
// Get handle for standard output
g_hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
fname = lpszCommandLine = lpszOrgCommandLine = GetCommandLine();
// Skip past program name (first token in command line)
// Check for and handle quoted program name
if (*lpszCommandLine == '"') {
// Scan, and skip over, subsequent characters until another
// double-quote or a null is encountered
do {
lpszCommandLine++;
} while (*lpszCommandLine && (*lpszCommandLine != '"'));
// If we stopped on a double-quote (usual case), skip over it.
if (*lpszCommandLine == '"') {
*lpszCommandLine++ = '\0';
}
} else {
// First token wasn't a quote
while (*lpszCommandLine > ' ') {
lpszCommandLine++ ;
}
}
// skip past any white space preceeding the second token.
while (*lpszCommandLine && (*lpszCommandLine <= ' ')) {
*lpszCommandLine++ = '\0';
}
if (*lpszCommandLine == '\0') {
usage();
return 1;
}
// GetModuleFileName(NULL, buf, _MAX_PATH /*sizeof(buf)*/);
p = fname + lstrlen(fname);
if (*(p - 4) == '.') { // cut ".ext"
p -= 4;
*p = '\0';
}
for (i = 0; i < numberof(dllinfo); i++) {
fname = p - lstrlen(dllinfo[i].ModuleName);
if (lpszOrgCommandLine < fname) {
char c = *(fname - 1);
if (c > ' ' && c != '\\' && c != ':' && c != '\"')
continue;
}
if (lstrcmpi(fname, dllinfo[i].ModuleName) == 0) {
hDLL = LoadLibrary(dllinfo[i].DLLName);
if (hDLL == NULL) {
myfputs("Can't load the DLL.\n", g_hStdOut);
return 2;
}
break;
}
}
if (hDLL == NULL) {
usage();
return 1;
}
ArcMainProc = (ARC_MAINPROC) GetProcAddress(hDLL, dllinfo[i].MainProc);
// wsprintf(buf, "%sGetVersion", dllinfo[i].MainProc);
// ArcGetVersion = (ARC_GETVERSION) GetProcAddress(hDLL, buf);
// wVer = ArcGetVersion();
ret = ArcMainProc(NULL, lpszCommandLine, buf, sizeof(buf));
FreeLibrary(hDLL);
buf[sizeof(buf) - 1] = '\0';
myfputs(buf, g_hStdOut);
return ret;
}