diff --git a/dlls/kernel/kernel32.spec b/dlls/kernel/kernel32.spec index 32b6c4a922a..787a8640c78 100644 --- a/dlls/kernel/kernel32.spec +++ b/dlls/kernel/kernel32.spec @@ -37,9 +37,9 @@ debug_channels (comm debugstr dll int resource stress thunk toolhelp win32) 17 register -i386 CommonUnimpStub() CommonUnimpStub 18 stdcall GetProcessDword(long long) GetProcessDword 19 stub ThunkTheTemplateHandle - 20 stub DosFileHandleToWin32Handle - 21 stub Win32HandleToDosFileHandle - 22 stub DisposeLZ32Handle + 20 stdcall DosFileHandleToWin32Handle(long) DosFileHandleToWin32Handle + 21 stdcall Win32HandleToDosFileHandle(long) Win32HandleToDosFileHandle + 22 stdcall DisposeLZ32Handle(long) DisposeLZ32Handle 23 stub GDIReallyCares 24 stdcall GlobalAlloc16(long long) GlobalAlloc16 25 stdcall GlobalLock16(long) GlobalLock16 @@ -71,23 +71,23 @@ debug_channels (comm debugstr dll int resource stress thunk toolhelp win32) 51 register -i386 W32S_BackTo32() W32S_BackTo32 52 stdcall GetThunkBuff() GetThunkBuff 53 stdcall GetThunkStuff(str str) GetThunkStuff - 54 stdcall K32WOWCallback16(long long) WOWCallback16 - 55 stdcall K32WOWCallback16Ex(ptr long long ptr ptr) WOWCallback16Ex - 56 stdcall K32WOWGetVDMPointer(long long long) WOWGetVDMPointer - 57 stdcall K32WOWHandle32(long long) WOWHandle32 - 58 stdcall K32WOWHandle16(long long) WOWHandle16 - 59 stdcall K32WOWGlobalAlloc16(long long) WOWGlobalAlloc16 - 60 stdcall K32WOWGlobalLock16(long) WOWGlobalLock16 - 61 stdcall K32WOWGlobalUnlock16(long) WOWGlobalUnlock16 - 62 stdcall K32WOWGlobalFree16(long) WOWGlobalFree16 - 63 stdcall K32WOWGlobalAllocLock16(long long ptr) WOWGlobalAllocLock16 - 64 stdcall K32WOWGlobalUnlockFree16(long) WOWGlobalUnlockFree16 - 65 stdcall K32WOWGlobalLockSize16(long ptr) WOWGlobalLockSize16 - 66 stdcall K32WOWYield16() WOWYield16 - 67 stdcall K32WOWDirectedYield16(long) WOWDirectedYield16 - 68 stdcall K32WOWGetVDMPointerFix(long long long) WOWGetVDMPointerFix - 69 stdcall K32WOWGetVDMPointerUnfix(long) WOWGetVDMPointerUnfix - 70 stdcall K32WOWGetDescriptor(long long) WOWGetDescriptor + 54 stdcall K32WOWCallback16(long long) K32WOWCallback16 + 55 stdcall K32WOWCallback16Ex(ptr long long ptr ptr) K32WOWCallback16Ex + 56 stdcall K32WOWGetVDMPointer(long long long) K32WOWGetVDMPointer + 57 stdcall K32WOWHandle32(long long) K32WOWHandle32 + 58 stdcall K32WOWHandle16(long long) K32WOWHandle16 + 59 stdcall K32WOWGlobalAlloc16(long long) K32WOWGlobalAlloc16 + 60 stdcall K32WOWGlobalLock16(long) K32WOWGlobalLock16 + 61 stdcall K32WOWGlobalUnlock16(long) K32WOWGlobalUnlock16 + 62 stdcall K32WOWGlobalFree16(long) K32WOWGlobalFree16 + 63 stdcall K32WOWGlobalAllocLock16(long long ptr) K32WOWGlobalAllocLock16 + 64 stdcall K32WOWGlobalUnlockFree16(long) K32WOWGlobalUnlockFree16 + 65 stdcall K32WOWGlobalLockSize16(long ptr) K32WOWGlobalLockSize16 + 66 stdcall K32WOWYield16() K32WOWYield16 + 67 stdcall K32WOWDirectedYield16(long) K32WOWDirectedYield16 + 68 stdcall K32WOWGetVDMPointerFix(long long long) K32WOWGetVDMPointerFix + 69 stdcall K32WOWGetVDMPointerUnfix(long) K32WOWGetVDMPointerUnfix + 70 stdcall K32WOWGetDescriptor(long long) K32WOWGetDescriptor 71 stub IsThreadId 72 forward K32RtlLargeIntegerAdd ntdll.RtlLargeIntegerAdd 73 forward K32RtlEnlargedIntegerMultiply ntdll.RtlEnlargedIntegerMultiply diff --git a/dlls/kernel/thunk.c b/dlls/kernel/thunk.c index a6ac464b255..2a57685e51b 100644 --- a/dlls/kernel/thunk.c +++ b/dlls/kernel/thunk.c @@ -1038,7 +1038,6 @@ void WINAPI GetTEBSelectorFS16(void) /********************************************************************** * KERNEL_431 (KERNEL.431) - * IsPeFormat (W32SYS.2) * Checks the passed filename if it is a PE format executeable * RETURNS * TRUE, if it is. @@ -1048,32 +1047,22 @@ BOOL16 WINAPI IsPeFormat16( LPSTR fn, /* [in] filename to executeable */ HFILE16 hf16 /* [in] open file, if filename is NULL */ ) { - IMAGE_DOS_HEADER mzh; - OFSTRUCT ofs; - DWORD xmagic; + BOOL ret = FALSE; + IMAGE_DOS_HEADER mzh; + OFSTRUCT ofs; + DWORD xmagic; - if (fn) { - hf16 = OpenFile16(fn,&ofs,OF_READ); - if (hf16==HFILE_ERROR16) - return FALSE; - } - _llseek16(hf16,0,SEEK_SET); - if (sizeof(mzh)!=_lread16(hf16,&mzh,sizeof(mzh))) { - _lclose(hf16); - return FALSE; - } - if (mzh.e_magic!=IMAGE_DOS_SIGNATURE) { - WARN("File has not got dos signature!\n"); - _lclose(hf16); - return FALSE; - } - _llseek16(hf16,mzh.e_lfanew,SEEK_SET); - if (sizeof(DWORD)!=_lread16(hf16,&xmagic,sizeof(DWORD))) { - _lclose(hf16); - return FALSE; - } - _lclose(hf16); - return (xmagic == IMAGE_NT_SIGNATURE); + if (fn) hf16 = OpenFile16(fn,&ofs,OF_READ); + if (hf16 == HFILE_ERROR16) return FALSE; + _llseek16(hf16,0,SEEK_SET); + if (sizeof(mzh)!=_lread16(hf16,&mzh,sizeof(mzh))) goto done; + if (mzh.e_magic!=IMAGE_DOS_SIGNATURE) goto done; + _llseek16(hf16,mzh.e_lfanew,SEEK_SET); + if (sizeof(DWORD)!=_lread16(hf16,&xmagic,sizeof(DWORD))) goto done; + ret = (xmagic == IMAGE_NT_SIGNATURE); + done: + _lclose16(hf16); + return ret; } @@ -1341,7 +1330,7 @@ void WINAPI C16ThkSL01(CONTEXT86 *context) struct ThunkDataSL16 *SL16 = PTR_SEG_TO_LIN(context->Edx); struct ThunkDataSL *td = SL16->fpData; - DWORD procAddress = (DWORD)GetProcAddress16(GetModuleHandle16("KERNEL"), 631); + DWORD procAddress = (DWORD)GetProcAddress16(GetModuleHandle16("KERNEL"), (LPCSTR)631); WORD cs = __get_cs(); if (!td) @@ -1781,7 +1770,7 @@ INT16 WINAPI UnRegisterCBClient16( INT16 wCBCId, void WINAPI InitCBClient16( FARPROC glueLS ) { HMODULE16 kernel = GetModuleHandle16( "KERNEL" ); - SEGPTR glueSL = (SEGPTR)WIN32_GetProcAddress16( kernel, (LPCSTR)604 ); + SEGPTR glueSL = (SEGPTR)GetProcAddress16( kernel, (LPCSTR)604 ); SetThunkletCallbackGlue16( glueLS, glueSL ); } @@ -1870,7 +1859,7 @@ SEGPTR WINAPI Get16DLLAddress(HMODULE handle, LPSTR func_name) { DWORD proc_16; if (!handle) handle=GetModuleHandle16("WIN32S16"); - proc_16 = (DWORD)WIN32_GetProcAddress16(handle, func_name); + proc_16 = (DWORD)GetProcAddress16(handle, func_name); x=PTR_SEG_TO_LIN(thunk); *x++=0xba; *(DWORD*)x=proc_16;x+=4; /* movl proc_16, $edx */ diff --git a/dlls/kernel/utthunk.c b/dlls/kernel/utthunk.c index 2fe15fca5a7..bbbb3fcfdf4 100644 --- a/dlls/kernel/utthunk.c +++ b/dlls/kernel/utthunk.c @@ -229,7 +229,7 @@ BOOL WINAPI UTRegister( HMODULE hModule, LPSTR lpsz16BITDLL, /* Load 16-bit DLL and get UTProc16 entry point */ if ( (hModule16 = LoadLibrary16( lpsz16BITDLL )) <= 32 - || (target16 = WIN32_GetProcAddress16( hModule16, lpszProcName )) == 0 ) + || (target16 = GetProcAddress16( hModule16, lpszProcName )) == 0 ) return FALSE; /* Allocate UTINFO struct */ @@ -250,7 +250,7 @@ BOOL WINAPI UTRegister( HMODULE hModule, LPSTR lpsz16BITDLL, /* Call UTInit16 if present */ if ( lpszInitName - && (init16 = WIN32_GetProcAddress16( hModule16, lpszInitName )) != 0 ) + && (init16 = GetProcAddress16( hModule16, lpszInitName )) != 0 ) { SEGPTR callback = SEGPTR_GET( &ut->ut16 ); SEGPTR segBuff = MapLS( lpBuff ); diff --git a/dlls/kernel/wowthunk.c b/dlls/kernel/wowthunk.c index 9cf189430b8..4ed24f029d3 100644 --- a/dlls/kernel/wowthunk.c +++ b/dlls/kernel/wowthunk.c @@ -39,18 +39,18 @@ DWORD WINAPI CallProcEx32W16(VOID); */ /********************************************************************** - * WOWGetDescriptor (WOW32.1) (KERNEL32.70) + * K32WOWGetDescriptor (WOW32.1) (KERNEL32.70) */ -BOOL WINAPI WOWGetDescriptor( SEGPTR segptr, LPLDT_ENTRY ldtent ) +BOOL WINAPI K32WOWGetDescriptor( SEGPTR segptr, LPLDT_ENTRY ldtent ) { return GetThreadSelectorEntry( GetCurrentThread(), segptr >> 16, ldtent ); } /********************************************************************** - * WOWGetVDMPointer (WOW32.5) (KERNEL32.56) + * K32WOWGetVDMPointer (WOW32.5) (KERNEL32.56) */ -LPVOID WINAPI WOWGetVDMPointer( DWORD vp, DWORD dwBytes, BOOL fProtectedMode ) +LPVOID WINAPI K32WOWGetVDMPointer( DWORD vp, DWORD dwBytes, BOOL fProtectedMode ) { /* FIXME: add size check too */ @@ -61,9 +61,9 @@ LPVOID WINAPI WOWGetVDMPointer( DWORD vp, DWORD dwBytes, BOOL fProtectedMode ) } /********************************************************************** - * WOWGetVDMPointerFix (WOW32.6) (KERNEL32.68) + * K32WOWGetVDMPointerFix (WOW32.6) (KERNEL32.68) */ -LPVOID WINAPI WOWGetVDMPointerFix( DWORD vp, DWORD dwBytes, BOOL fProtectedMode ) +LPVOID WINAPI K32WOWGetVDMPointerFix( DWORD vp, DWORD dwBytes, BOOL fProtectedMode ) { /* * Hmmm. According to the docu, we should call: @@ -77,13 +77,13 @@ LPVOID WINAPI WOWGetVDMPointerFix( DWORD vp, DWORD dwBytes, BOOL fProtectedMode * fProtectedMode is TRUE, anyway ...) */ - return WOWGetVDMPointer( vp, dwBytes, fProtectedMode ); + return K32WOWGetVDMPointer( vp, dwBytes, fProtectedMode ); } /********************************************************************** - * WOWGetVDMPointerUnFix (WOW32.7) (KERNEL32.69) + * K32WOWGetVDMPointerUnFix (WOW32.7) (KERNEL32.69) */ -VOID WINAPI WOWGetVDMPointerUnfix( DWORD vp ) +VOID WINAPI K32WOWGetVDMPointerUnfix( DWORD vp ) { /* * See above why we don't call: @@ -94,75 +94,75 @@ VOID WINAPI WOWGetVDMPointerUnfix( DWORD vp ) } /********************************************************************** - * WOWGlobalAlloc16 (WOW32.8) (KERNEL32.59) + * K32WOWGlobalAlloc16 (WOW32.8) (KERNEL32.59) */ -WORD WINAPI WOWGlobalAlloc16( WORD wFlags, DWORD cb ) +WORD WINAPI K32WOWGlobalAlloc16( WORD wFlags, DWORD cb ) { return (WORD)GlobalAlloc16( wFlags, cb ); } /********************************************************************** - * WOWGlobalFree16 (WOW32.10) (KERNEL32.62) + * K32WOWGlobalFree16 (WOW32.10) (KERNEL32.62) */ -WORD WINAPI WOWGlobalFree16( WORD hMem ) +WORD WINAPI K32WOWGlobalFree16( WORD hMem ) { return (WORD)GlobalFree16( (HGLOBAL16)hMem ); } /********************************************************************** - * WOWGlobalLock16 (WOW32.11) (KERNEL32.60) + * K32WOWGlobalLock16 (WOW32.11) (KERNEL32.60) */ -DWORD WINAPI WOWGlobalLock16( WORD hMem ) +DWORD WINAPI K32WOWGlobalLock16( WORD hMem ) { return (DWORD)WIN16_GlobalLock16( (HGLOBAL16)hMem ); } /********************************************************************** - * WOWGlobalUnlock16 (WOW32.13) (KERNEL32.61) + * K32WOWGlobalUnlock16 (WOW32.13) (KERNEL32.61) */ -BOOL WINAPI WOWGlobalUnlock16( WORD hMem ) +BOOL WINAPI K32WOWGlobalUnlock16( WORD hMem ) { return (BOOL)GlobalUnlock16( (HGLOBAL16)hMem ); } /********************************************************************** - * WOWGlobalAllocLock16 (WOW32.9) (KERNEL32.63) + * K32WOWGlobalAllocLock16 (WOW32.9) (KERNEL32.63) */ -DWORD WINAPI WOWGlobalAllocLock16( WORD wFlags, DWORD cb, WORD *phMem ) +DWORD WINAPI K32WOWGlobalAllocLock16( WORD wFlags, DWORD cb, WORD *phMem ) { - WORD hMem = WOWGlobalAlloc16( wFlags, cb ); + WORD hMem = K32WOWGlobalAlloc16( wFlags, cb ); if (phMem) *phMem = hMem; - return WOWGlobalLock16( hMem ); + return K32WOWGlobalLock16( hMem ); } /********************************************************************** - * WOWGlobalLockSize16 (WOW32.12) (KERNEL32.65) + * K32WOWGlobalLockSize16 (WOW32.12) (KERNEL32.65) */ -DWORD WINAPI WOWGlobalLockSize16( WORD hMem, PDWORD pcb ) +DWORD WINAPI K32WOWGlobalLockSize16( WORD hMem, PDWORD pcb ) { if ( pcb ) *pcb = GlobalSize16( (HGLOBAL16)hMem ); - return WOWGlobalLock16( hMem ); + return K32WOWGlobalLock16( hMem ); } /********************************************************************** - * WOWGlobalUnlockFree16 (WOW32.14) (KERNEL32.64) + * K32WOWGlobalUnlockFree16 (WOW32.14) (KERNEL32.64) */ -WORD WINAPI WOWGlobalUnlockFree16( DWORD vpMem ) +WORD WINAPI K32WOWGlobalUnlockFree16( DWORD vpMem ) { - if ( !WOWGlobalUnlock16( HIWORD(vpMem) ) ) + if ( !K32WOWGlobalUnlock16( HIWORD(vpMem) ) ) return FALSE; - return WOWGlobalFree16( HIWORD(vpMem) ); + return K32WOWGlobalFree16( HIWORD(vpMem) ); } /********************************************************************** - * WOWYield16 (WOW32.17) (KERNEL32.66) + * K32WOWYield16 (WOW32.17) (KERNEL32.66) */ -VOID WINAPI WOWYield16( void ) +VOID WINAPI K32WOWYield16( void ) { /* * This does the right thing for both Win16 and Win32 tasks. @@ -172,9 +172,9 @@ VOID WINAPI WOWYield16( void ) } /********************************************************************** - * WOWDirectedYield16 (WOW32.4) (KERNEL32.67) + * K32WOWDirectedYield16 (WOW32.4) (KERNEL32.67) */ -VOID WINAPI WOWDirectedYield16( WORD htask16 ) +VOID WINAPI K32WOWDirectedYield16( WORD htask16 ) { /* * Argh. Our scheduler doesn't like DirectedYield by Win32 @@ -186,9 +186,9 @@ VOID WINAPI WOWDirectedYield16( WORD htask16 ) /*********************************************************************** - * WOWHandle32 (WOW32.16) (KERNEL32.57) + * K32WOWHandle32 (WOW32.16) (KERNEL32.57) */ -HANDLE WINAPI WOWHandle32( WORD handle, WOW_HANDLE_TYPE type ) +HANDLE WINAPI K32WOWHandle32( WORD handle, WOW_HANDLE_TYPE type ) { switch ( type ) { @@ -216,9 +216,9 @@ HANDLE WINAPI WOWHandle32( WORD handle, WOW_HANDLE_TYPE type ) } /*********************************************************************** - * WOWHandle16 (WOW32.15) (KERNEL32.58) + * K32WOWHandle16 (WOW32.15) (KERNEL32.58) */ -WORD WINAPI WOWHandle16( HANDLE handle, WOW_HANDLE_TYPE type ) +WORD WINAPI K32WOWHandle16( HANDLE handle, WOW_HANDLE_TYPE type ) { if ( HIWORD(handle ) ) ERR( "handle 0x%08x of type %d has non-zero HIWORD\n", handle, type ); @@ -249,24 +249,10 @@ WORD WINAPI WOWHandle16( HANDLE handle, WOW_HANDLE_TYPE type ) } /********************************************************************** - * WOWCallback16 (WOW32.2) (KERNEL32.54) + * K32WOWCallback16Ex (WOW32.3) (KERNEL32.55) */ -DWORD WINAPI WOWCallback16( DWORD vpfn16, DWORD dwParam ) -{ - DWORD ret; - - if ( !WOWCallback16Ex( vpfn16, WCB16_PASCAL, - sizeof(DWORD), &dwParam, &ret ) ) - ret = 0L; - - return ret; -} - -/********************************************************************** - * WOWCallback16Ex (WOW32.3) (KERNEL32.55) - */ -BOOL WINAPI WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, - DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode ) +BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, + DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode ) { DWORD ret; @@ -293,6 +279,19 @@ BOOL WINAPI WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, return TRUE; /* success */ } +/********************************************************************** + * K32WOWCallback16 (WOW32.2) (KERNEL32.54) + */ +DWORD WINAPI K32WOWCallback16( DWORD vpfn16, DWORD dwParam ) +{ + DWORD ret; + + if ( !K32WOWCallback16Ex( vpfn16, WCB16_PASCAL, + sizeof(DWORD), &dwParam, &ret ) ) + ret = 0L; + + return ret; +} /* @@ -304,7 +303,7 @@ BOOL WINAPI WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, */ DWORD WINAPI GetVDMPointer32W16( SEGPTR vp, UINT16 fMode ) { - return (DWORD)WOWGetVDMPointer( vp, 0, (DWORD)fMode ); + return (DWORD)K32WOWGetVDMPointer( vp, 0, (DWORD)fMode ); } /*********************************************************************** diff --git a/dlls/lzexpand/Makefile.in b/dlls/lzexpand/Makefile.in index 833c3396c4d..295be265be6 100644 --- a/dlls/lzexpand/Makefile.in +++ b/dlls/lzexpand/Makefile.in @@ -4,7 +4,7 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = lz32 ALTNAMES = lzexpand -IMPORTS = ntdll +EXTRALIBS = -lwine_unicode LDDLLFLAGS = @LDDLLFLAGS@ SYMBOLFILE = $(MODULE).tmp.o diff --git a/dlls/lzexpand/lzexpand_main.c b/dlls/lzexpand/lzexpand_main.c index bc31e16fc5c..ede2a3066b1 100644 --- a/dlls/lzexpand/lzexpand_main.c +++ b/dlls/lzexpand/lzexpand_main.c @@ -15,8 +15,7 @@ #include "winbase.h" #include "wine/winbase16.h" #include "wine/winestring.h" -#include "file.h" -#include "heap.h" +#include "wine/unicode.h" #include "lzexpand.h" #include "debugtools.h" @@ -152,7 +151,7 @@ INT WINAPI LZStart(void) */ HFILE16 WINAPI LZInit16( HFILE16 hfSrc ) { - HFILE ret = LZInit( FILE_GetHandle(hfSrc) ); + HFILE ret = LZInit( DosFileHandleToWin32Handle(hfSrc) ); if (IS_LZ_HANDLE(ret)) return ret; if ((INT)ret <= 0) return ret; return hfSrc; @@ -313,16 +312,16 @@ INT WINAPI GetExpandedNameA( LPCSTR in, LPSTR out ) */ INT WINAPI GetExpandedNameW( LPCWSTR in, LPWSTR out ) { - char *xin,*xout; - INT ret; - - xout = HeapAlloc( GetProcessHeap(), 0, lstrlenW(in)+3 ); - xin = HEAP_strdupWtoA( GetProcessHeap(), 0, in ); - ret = GetExpandedName16(xin,xout); - if (ret>0) lstrcpyAtoW(out,xout); - HeapFree( GetProcessHeap(), 0, xin ); - HeapFree( GetProcessHeap(), 0, xout ); - return ret; + INT ret; + DWORD len = WideCharToMultiByte( CP_ACP, 0, in, -1, NULL, 0, NULL, NULL ); + char *xin = HeapAlloc( GetProcessHeap(), 0, len ); + char *xout = HeapAlloc( GetProcessHeap(), 0, len+3 ); + WideCharToMultiByte( CP_ACP, 0, in, -1, xin, len, NULL, NULL ); + if ((ret = GetExpandedNameA( xin, xout )) > 0) + MultiByteToWideChar( CP_ACP, 0, xout, -1, out, strlenW(in)+4 ); + HeapFree( GetProcessHeap(), 0, xin ); + HeapFree( GetProcessHeap(), 0, xout ); + return ret; } @@ -332,7 +331,7 @@ INT WINAPI GetExpandedNameW( LPCWSTR in, LPWSTR out ) INT16 WINAPI LZRead16( HFILE16 fd, LPVOID buf, UINT16 toread ) { if (IS_LZ_HANDLE(fd)) return LZRead( fd, buf, toread ); - return _lread( FILE_GetHandle(fd), buf, toread ); + return _lread( DosFileHandleToWin32Handle(fd), buf, toread ); } @@ -433,7 +432,7 @@ INT WINAPI LZRead( HFILE fd, LPVOID vbuf, UINT toread ) LONG WINAPI LZSeek16( HFILE16 fd, LONG off, INT16 type ) { if (IS_LZ_HANDLE(fd)) return LZSeek( fd, off, type ); - return _llseek( FILE_GetHandle(fd), off, type ); + return _llseek( DosFileHandleToWin32Handle(fd), off, type ); } @@ -476,19 +475,19 @@ LONG WINAPI LZSeek( HFILE fd, LONG off, INT type ) LONG WINAPI LZCopy16( HFILE16 src, HFILE16 dest ) { /* already a LZ handle? */ - if (IS_LZ_HANDLE(src)) return LZCopy( src, FILE_GetHandle(dest) ); + if (IS_LZ_HANDLE(src)) return LZCopy( src, DosFileHandleToWin32Handle(dest) ); /* no, try to open one */ src = LZInit16(src); if ((INT16)src <= 0) return 0; if (IS_LZ_HANDLE(src)) { - LONG ret = LZCopy( src, FILE_GetHandle(dest) ); + LONG ret = LZCopy( src, DosFileHandleToWin32Handle(dest) ); LZClose( src ); return ret; } /* it was not a compressed file */ - return LZCopy( FILE_GetHandle(src), FILE_GetHandle(dest) ); + return LZCopy( DosFileHandleToWin32Handle(src), DosFileHandleToWin32Handle(dest) ); } @@ -576,7 +575,7 @@ HFILE16 WINAPI LZOpenFile16( LPCSTR fn, LPOFSTRUCT ofs, UINT16 mode ) if ((INT)hfret <= 0) return hfret; if (IS_LZ_HANDLE(hfret)) return hfret; /* but allocate a dos handle for 'normal' files */ - return FILE_AllocDosHandle(hfret); + return Win32HandleToDosFileHandle(hfret); } @@ -613,20 +612,13 @@ HFILE WINAPI LZOpenFileA( LPCSTR fn, LPOFSTRUCT ofs, UINT mode ) */ HFILE WINAPI LZOpenFileW( LPCWSTR fn, LPOFSTRUCT ofs, UINT mode ) { - LPSTR xfn; - LPWSTR yfn; - HFILE ret; - - xfn = HEAP_strdupWtoA( GetProcessHeap(), 0, fn); - ret = LZOpenFile16(xfn,ofs,mode); - HeapFree( GetProcessHeap(), 0, xfn ); - if (ret!=HFILE_ERROR) { - /* ofs->szPathName is an array with the OFSTRUCT */ - yfn = HEAP_strdupAtoW( GetProcessHeap(), 0, ofs->szPathName ); - memcpy(ofs->szPathName,yfn,lstrlenW(yfn)*2+2); - HeapFree( GetProcessHeap(), 0, yfn ); - } - return ret; + HFILE ret; + DWORD len = WideCharToMultiByte( CP_ACP, 0, fn, -1, NULL, 0, NULL, NULL ); + LPSTR xfn = HeapAlloc( GetProcessHeap(), 0, len ); + WideCharToMultiByte( CP_ACP, 0, fn, -1, xfn, len, NULL, NULL ); + ret = LZOpenFileA(xfn,ofs,mode); + HeapFree( GetProcessHeap(), 0, xfn ); + return ret; } @@ -636,7 +628,7 @@ HFILE WINAPI LZOpenFileW( LPCWSTR fn, LPOFSTRUCT ofs, UINT mode ) void WINAPI LZClose16( HFILE16 fd ) { if (IS_LZ_HANDLE(fd)) LZClose( fd ); - else _lclose16( fd ); + else DisposeLZ32Handle( DosFileHandleToWin32Handle(fd) ); } diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 88a4b212965..c30274e074f 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -582,6 +582,8 @@ HRESULT WINAPI StringFromCLSID16( LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */ ) { + extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, + DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode ); LPMALLOC16 mllc; HRESULT ret; DWORD args[2]; @@ -595,7 +597,7 @@ HRESULT WINAPI StringFromCLSID16( /* No need for a Callback entry, we have WOWCallback16Ex which does * everything we need. */ - if (!WOWCallback16Ex( + if (!K32WOWCallback16Ex( (DWORD)((ICOM_VTABLE(IMalloc16)*)PTR_SEG_TO_LIN( ICOM_VTBL(((LPMALLOC16)PTR_SEG_TO_LIN(mllc)))) )->fnAlloc, diff --git a/files/file.c b/files/file.c index bb1d18c76c5..3639a210faf 100644 --- a/files/file.c +++ b/files/file.c @@ -1033,7 +1033,7 @@ success: /* We get here if the open was successful */ } else { - hFileRet = FILE_AllocDosHandle( hFileRet ); + hFileRet = Win32HandleToDosFileHandle( hFileRet ); if (hFileRet == HFILE_ERROR16) goto error; if (mode & OF_EXIST) /* Return the handle, but close it first */ _lclose16( hFileRet ); @@ -1075,7 +1075,7 @@ HFILE WINAPI OpenFile( LPCSTR name, OFSTRUCT *ofs, UINT mode ) * FILE_InitProcessDosHandles * * Allocates the default DOS handles for a process. Called either by - * AllocDosHandle below or by the DOSVM stuff. + * Win32HandleToDosFileHandle below or by the DOSVM stuff. */ static void FILE_InitProcessDosHandles( void ) { @@ -1087,38 +1087,47 @@ static void FILE_InitProcessDosHandles( void ) } /*********************************************************************** - * FILE_AllocDosHandle + * Win32HandleToDosFileHandle (KERNEL32.21) * * Allocate a DOS handle for a Win32 handle. The Win32 handle is no * longer valid after this function (even on failure). + * + * Note: this is not exactly right, since on Win95 the Win32 handles + * are on top of DOS handles and we do it the other way + * around. Should be good enough though. */ -HFILE16 FILE_AllocDosHandle( HANDLE handle ) +HFILE WINAPI Win32HandleToDosFileHandle( HANDLE handle ) { int i; if (!handle || (handle == INVALID_HANDLE_VALUE)) - return INVALID_HANDLE_VALUE16; + return HFILE_ERROR; for (i = 5; i < DOS_TABLE_SIZE; i++) if (!dos_handles[i]) { dos_handles[i] = handle; TRACE("Got %d for h32 %d\n", i, handle ); - return i; + return (HFILE)i; } CloseHandle( handle ); SetLastError( ERROR_TOO_MANY_OPEN_FILES ); - return INVALID_HANDLE_VALUE16; + return HFILE_ERROR; } /*********************************************************************** - * FILE_GetHandle + * DosFileHandleToWin32Handle (KERNEL32.20) * * Return the Win32 handle for a DOS handle. + * + * Note: this is not exactly right, since on Win95 the Win32 handles + * are on top of DOS handles and we do it the other way + * around. Should be good enough though. */ -HANDLE FILE_GetHandle( HFILE16 hfile ) +HANDLE WINAPI DosFileHandleToWin32Handle( HFILE handle ) { + HFILE16 hfile = (HFILE16)handle; if (hfile < 5 && !dos_handles[hfile]) FILE_InitProcessDosHandles(); if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile]) { @@ -1129,6 +1138,30 @@ HANDLE FILE_GetHandle( HFILE16 hfile ) } +/*********************************************************************** + * DisposeLZ32Handle (KERNEL32.22) + * + * Note: this is not entirely correct, we should only close the + * 32-bit handle and not the 16-bit one, but we cannot do + * this because of the way our DOS handles are implemented. + * It shouldn't break anything though. + */ +void WINAPI DisposeLZ32Handle( HANDLE handle ) +{ + int i; + + if (!handle || (handle == INVALID_HANDLE_VALUE)) return; + + for (i = 5; i < DOS_TABLE_SIZE; i++) + if (dos_handles[i] == handle) + { + dos_handles[i] = 0; + CloseHandle( handle ); + break; + } +} + + /*********************************************************************** * FILE_Dup2 * @@ -1291,7 +1324,7 @@ LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count ) /* Some programs pass a count larger than the allocated buffer */ maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1; if (count > maxlen) count = maxlen; - return _lread(FILE_GetHandle(hFile), PTR_SEG_TO_LIN(buffer), count ); + return _lread(DosFileHandleToWin32Handle(hFile), PTR_SEG_TO_LIN(buffer), count ); } @@ -1320,7 +1353,7 @@ UINT WINAPI _lread( HFILE handle, LPVOID buffer, UINT count ) */ UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count ) { - return (UINT16)_lread(FILE_GetHandle(hFile), buffer, (LONG)count ); + return (UINT16)_lread(DosFileHandleToWin32Handle(hFile), buffer, (LONG)count ); } @@ -1329,7 +1362,7 @@ UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count ) */ HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr ) { - return FILE_AllocDosHandle( _lcreat( path, attr ) ); + return Win32HandleToDosFileHandle( _lcreat( path, attr ) ); } @@ -1397,7 +1430,7 @@ DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, */ LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin ) { - return SetFilePointer( FILE_GetHandle(hFile), lOffset, NULL, nOrigin ); + return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin ); } @@ -1415,7 +1448,7 @@ LONG WINAPI _llseek( HFILE hFile, LONG lOffset, INT nOrigin ) */ HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode ) { - return FILE_AllocDosHandle( _lopen( path, mode ) ); + return Win32HandleToDosFileHandle( _lopen( path, mode ) ); } @@ -1437,7 +1470,7 @@ HFILE WINAPI _lopen( LPCSTR path, INT mode ) */ UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count ) { - return (UINT16)_hwrite( FILE_GetHandle(hFile), buffer, (LONG)count ); + return (UINT16)_hwrite( DosFileHandleToWin32Handle(hFile), buffer, (LONG)count ); } /*********************************************************************** @@ -1454,7 +1487,7 @@ UINT WINAPI _lwrite( HFILE hFile, LPCSTR buffer, UINT count ) */ LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count) { - return _lread( FILE_GetHandle(hFile), buffer, count ); + return _lread( DosFileHandleToWin32Handle(hFile), buffer, count ); } @@ -1472,7 +1505,7 @@ LONG WINAPI _hread( HFILE hFile, LPVOID buffer, LONG count) */ LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count ) { - return _hwrite( FILE_GetHandle(hFile), buffer, count ); + return _hwrite( DosFileHandleToWin32Handle(hFile), buffer, count ); } diff --git a/include/file.h b/include/file.h index 2cd38648c16..3a22525b431 100644 --- a/include/file.h +++ b/include/file.h @@ -42,8 +42,6 @@ extern HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, DWORD attributes, HANDLE template, BOOL fail_read_only ); extern HFILE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa ); -extern HFILE16 FILE_AllocDosHandle( HANDLE handle ); -extern HANDLE FILE_GetHandle( HFILE16 hfile ); /* files/directory.c */ extern int DIR_Init(void); diff --git a/include/winbase.h b/include/winbase.h index 663e4cac029..e4a7a6e8094 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -1880,12 +1880,15 @@ typedef struct tagSYSLEVEL INT level; } SYSLEVEL; +void WINAPI DisposeLZ32Handle(HANDLE); +HANDLE WINAPI DosFileHandleToWin32Handle(HFILE); VOID WINAPI GetpWin16Lock(SYSLEVEL**); DWORD WINAPI MapLS(LPVOID); LPVOID WINAPI MapSL(DWORD); VOID WINAPI ReleaseThunkLock(DWORD*); VOID WINAPI RestoreThunkLock(DWORD); VOID WINAPI UnMapLS(DWORD); +HFILE WINAPI Win32HandleToDosFileHandle(HANDLE); DWORD WINAPI _ConfirmWin16Lock(void); DWORD WINAPI _ConfirmSysLevel(SYSLEVEL*); VOID WINAPI _EnterSysLevel(SYSLEVEL*); diff --git a/loader/ne/segment.c b/loader/ne/segment.c index c2b0201fc5d..9953ee055ef 100644 --- a/loader/ne/segment.c +++ b/loader/ne/segment.c @@ -121,7 +121,7 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) pModule->self,hf,segnum ); DuplicateHandle( GetCurrentProcess(), hf, GetCurrentProcess(), &hFile32, 0, FALSE, DUPLICATE_SAME_ACCESS ); - hFile16 = FILE_AllocDosHandle( hFile32 ); + hFile16 = Win32HandleToDosFileHandle( hFile32 ); pSeg->hSeg = NE_CallTo16_word_www( selfloadheader->LoadAppSeg, pModule->self, hFile16, segnum ); TRACE_(dll)("Ret CallLoadAppSegProc: hSeg = 0x%04x\n", pSeg->hSeg); @@ -417,7 +417,7 @@ BOOL NE_LoadAllSegments( NE_MODULE *pModule ) DuplicateHandle( GetCurrentProcess(), NE_OpenFile(pModule), GetCurrentProcess(), &hf, 0, FALSE, DUPLICATE_SAME_ACCESS ); - hFile16 = FILE_AllocDosHandle( hf ); + hFile16 = Win32HandleToDosFileHandle( hf ); TRACE_(dll)("CallBootAppProc(hModule=0x%04x,hf=0x%04x)\n", pModule->self,hFile16); NE_CallTo16_word_ww(selfloadheader->BootApp, pModule->self,hFile16); diff --git a/msdos/int21.c b/msdos/int21.c index b1a7d736854..7670bf6800c 100644 --- a/msdos/int21.c +++ b/msdos/int21.c @@ -267,7 +267,7 @@ static void ioctlGetDeviceInfo( CONTEXT86 *context ) RESET_CFLAG(context); /* DOS device ? */ - if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) ))) + if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) ))) { DX_reg(context) = dev->flags; return; @@ -475,7 +475,7 @@ static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr ) { /* Mask off all flags not explicitly allowed by the doc */ attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM; - return FILE_AllocDosHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE, + return Win32HandleToDosFileHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW, attr, -1 )); } @@ -887,7 +887,7 @@ static void fLock( CONTEXT86 * context ) BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)), MAKELONG(DI_reg(context),SI_reg(context))) ; - if (!LockFile(FILE_GetHandle(BX_reg(context)), + if (!LockFile(DosFileHandleToWin32Handle(BX_reg(context)), MAKELONG(DX_reg(context),CX_reg(context)), 0, MAKELONG(DI_reg(context),SI_reg(context)), 0)) { AX_reg(context) = GetLastError(); @@ -900,7 +900,7 @@ static void fLock( CONTEXT86 * context ) BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)), MAKELONG(DI_reg(context),SI_reg(context))) ; - if (!UnlockFile(FILE_GetHandle(BX_reg(context)), + if (!UnlockFile(DosFileHandleToWin32Handle(BX_reg(context)), MAKELONG(DX_reg(context),CX_reg(context)), 0, MAKELONG(DI_reg(context),SI_reg(context)), 0)) { AX_reg(context) = GetLastError(); @@ -1628,7 +1628,7 @@ void WINAPI DOS3Call( CONTEXT86 *context ) break; case 0x02:{ const DOS_DEVICE *dev; - if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )) && + if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) )) && !strcasecmp( dev->name, "SCSIMGR$" )) { ASPI_DOS_HandleInt(context); @@ -1758,12 +1758,12 @@ void WINAPI DOS3Call( CONTEXT86 *context ) HANDLE handle; TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context)); if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(), - FILE_GetHandle(BX_reg(context)), + DosFileHandleToWin32Handle(BX_reg(context)), GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS ))) AX_reg(context) = HFILE_ERROR16; else - AX_reg(context) = FILE_AllocDosHandle(handle); + AX_reg(context) = Win32HandleToDosFileHandle(handle); break; } @@ -1930,7 +1930,7 @@ void WINAPI DOS3Call( CONTEXT86 *context ) FILETIME filetime; TRACE("GET FILE DATE AND TIME for handle %d\n", BX_reg(context)); - if (!GetFileTime( FILE_GetHandle(BX_reg(context)), NULL, NULL, &filetime )) + if (!GetFileTime( DosFileHandleToWin32Handle(BX_reg(context)), NULL, NULL, &filetime )) bSetDOSExtendedError = TRUE; else FileTimeToDosDateTime( &filetime, &DX_reg(context), &CX_reg(context) ); @@ -1945,7 +1945,7 @@ void WINAPI DOS3Call( CONTEXT86 *context ) DosDateTimeToFileTime( DX_reg(context), CX_reg(context), &filetime ); bSetDOSExtendedError = - (!SetFileTime( FILE_GetHandle(BX_reg(context)), + (!SetFileTime( DosFileHandleToWin32Handle(BX_reg(context)), NULL, NULL, &filetime )); } break; @@ -2119,7 +2119,7 @@ void WINAPI DOS3Call( CONTEXT86 *context ) case 0x68: /* "FFLUSH" - COMMIT FILE */ case 0x6a: /* COMMIT FILE */ TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context)); - bSetDOSExtendedError = (!FlushFileBuffers( FILE_GetHandle(BX_reg(context)) )); + bSetDOSExtendedError = (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) )); break; case 0x69: /* DISK SERIAL NUMBER */ diff --git a/msdos/vxd.c b/msdos/vxd.c index 69c791e19b9..09f8fa16f92 100644 --- a/msdos/vxd.c +++ b/msdos/vxd.c @@ -600,9 +600,8 @@ void WINAPI VXD_Win32s( CONTEXT86 *context ) if (!(PROCESS_Current()->flags & PDB32_WIN32S_PROC)) { HMODULE16 hModule = GetModuleHandle16("win32s16"); - SEGPTR func1 = (SEGPTR)WIN32_GetProcAddress16(hModule, "SetFS"); - SEGPTR func2 = (SEGPTR)WIN32_GetProcAddress16(hModule, - "StackLinearToSegmented"); + SEGPTR func1 = (SEGPTR)GetProcAddress16(hModule, "SetFS"); + SEGPTR func2 = (SEGPTR)GetProcAddress16(hModule, "StackLinearToSegmented"); if ( hModule && func1 && func2 && SELECTOROF(func1) == SELECTOROF(func2)) @@ -1073,7 +1072,7 @@ void WINAPI VXD_Win32s( CONTEXT86 *context ) LARGE_INTEGER *size = (LARGE_INTEGER *)W32S_APP2WINE(stack[3], W32S_OFFSET); DWORD protect = stack[4]; DWORD flags2 = stack[5]; - HFILE hFile = FILE_GetHandle(stack[6]); + HANDLE hFile = DosFileHandleToWin32Handle(stack[6]); DWORD psp = stack[7]; HANDLE result = INVALID_HANDLE_VALUE;