home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
MULTINST.PRG
< prev
next >
Wrap
Text File
|
1994-11-18
|
3KB
|
103 lines
//==================================
// MULTINST.C - Matt Pietrek 1993
//==================================
//
// Modified by: John Skelton, 18-Nov-94.
//
// Copyright (C) 1994 Skelton Software, Leeds, UK.
// All Rights Reserved.
#define MAKELP(sel, off) (off + (sel) * 65536)
#define SELECTOROF(ptr) C4W_HiWord(ptr)
#ifdef TESTING
function main()
local hWnd := WinSetup("test", "test")
? "Check for .T.: ", MultipleInstance()
wait
return 0
#endif // TESTING
// Central function that modifies a module table to trick the loader
// into letting a second instance of a multiple data segment program run.
function MultipleInstance(hInst)
/*
HMODULE hModuleSel
LPSTR moduleName, fileName
BYTE cbModuleName
*/
local hModuleSel
local moduleName, fileName
local cbModuleName
if hInst == nil
hInst = _GetInstance()
endif
hModuleSel = SELECTOROF( ; // Convert the HINSTANCE to an HMODULE
GlobalLock(GetModuleHandle(MAKELP(0,hInst))))
#ifdef TESTING
? hModuleSel
wait
#endif // TESTING
if hModuleSel == 0 // Make sure we succeeded.
return .f.
endif
// Make pointers to the resident names table and the OFSTRUCT
// moduleName = MAKELP( hModuleSel, *(WORD FAR *)MAKELP(hModuleSel, 0x26))
moduleName = MAKELP( hModuleSel, C4W_PeekW(MAKELP(hModuleSel, 38)))
// fileName = MAKELP( hModuleSel, *(WORD FAR *)MAKELP(hModuleSel, 0x0A))
fileName = MAKELP( hModuleSel, C4W_PeekW(MAKELP(hModuleSel, 10)))
// Get the module name length, and advance to the actual string
// cbModuleName = *moduleName++ // First byte is a length byte
cbModuleName = C4W_PeekB(moduleName++) // First byte is a length byte
#ifdef TESTING
? moduleName
? fileName
? cbModuleName
wait
#endif // TESTING
// Convert the first uppercase letter of the modulename to lowercase
do while cbModuleName != 0
if isupper(C4W_Peek(moduleName, 1))
C4W_Poke(moduleName, lower(C4W_Peek(moduleName, 1)))
exit
endif
cbModuleName-- ; moduleName++
enddo
if cbModuleName == 0 // Make sure we succeeded
return .f.
endif
// Position to the end of the filename. First byte is a length byte
fileName += C4W_PeekB(fileName) - 1
// Find the first uppercase letter in the filename. Convert to lowercase
do while .t.
// Stop when we come to a directory separator or colon
if C4W_Peek(fileName, 1) $ "\/:"
return .f.
endif
if isupper(C4W_Peek(fileName, 1))
C4W_Poke(fileName, lower(C4W_Peek(fileName, 1)))
exit
endif
fileName--
enddo
return .t.
static function GetModuleHandle(hInst)
local _c := GetProcAddress( , "GetModuleHandle", "P", "int", "dword")
return CallDLL(_c, hInst)