summaryrefslogtreecommitdiff
path: root/sal/systools
diff options
context:
space:
mode:
authorHennes Rohling <hro@openoffice.org>2002-08-14 13:33:20 +0000
committerHennes Rohling <hro@openoffice.org>2002-08-14 13:33:20 +0000
commit450b2cecfba6139cf6ed871f84f1eb3630006af5 (patch)
tree39aead20b45325f0696e848554ceaa4160aba02f /sal/systools
parent6808e84eaec8d4f7ce48386135ba4907605f9c17 (diff)
#91296# UWINAPI wrapper added
Diffstat (limited to 'sal/systools')
-rw-r--r--sal/systools/win32/uwinapi/CommandLineToArgvW.cpp144
-rw-r--r--sal/systools/win32/uwinapi/CopyFileExA.cpp138
-rw-r--r--sal/systools/win32/uwinapi/CopyFileExW.cpp11
-rw-r--r--sal/systools/win32/uwinapi/DrawStateW.cpp48
-rw-r--r--sal/systools/win32/uwinapi/GetLogicalDriveStringsW.cpp15
-rw-r--r--sal/systools/win32/uwinapi/GetLongPathName.cpp86
-rw-r--r--sal/systools/win32/uwinapi/GetLongPathNameA.cpp5
-rw-r--r--sal/systools/win32/uwinapi/GetLongPathNameW.cpp37
-rw-r--r--sal/systools/win32/uwinapi/MoveFileExA.cpp71
-rw-r--r--sal/systools/win32/uwinapi/MoveFileExW.cpp12
-rw-r--r--sal/systools/win32/uwinapi/ResolveThunk.cpp38
-rw-r--r--sal/systools/win32/uwinapi/SHILCreateFromPathW.cpp32
-rw-r--r--sal/systools/win32/uwinapi/Uwinapi.def22
-rw-r--r--sal/systools/win32/uwinapi/Uwinapi.h137
-rw-r--r--sal/systools/win32/uwinapi/makefile.mk121
-rw-r--r--sal/systools/win32/uwinapi/uwinapi.dxp20
16 files changed, 937 insertions, 0 deletions
diff --git a/sal/systools/win32/uwinapi/CommandLineToArgvW.cpp b/sal/systools/win32/uwinapi/CommandLineToArgvW.cpp
new file mode 100644
index 000000000..b072beaf1
--- /dev/null
+++ b/sal/systools/win32/uwinapi/CommandLineToArgvW.cpp
@@ -0,0 +1,144 @@
+#define _UWINAPI_
+#include "uwinapi.h"
+
+#ifdef __cplusplus
+#define local inline
+#else
+#define local static
+#endif
+
+local LPCWSTR SkipBlanks( LPCWSTR lpScan )
+{
+ while ( ' ' == *lpScan || '\t' == *lpScan )
+ lpScan++;
+
+ return lpScan;
+}
+
+
+local LPCWSTR SkipArgument( LPCWSTR lpScan )
+{
+ BOOL fQuoted = FALSE;
+ LPCWSTR lpArgEnd = NULL;
+
+ do
+ {
+ switch ( *lpScan )
+ {
+ case ' ':
+ case '\t':
+ if ( fQuoted )
+ lpScan++;
+ else
+ lpArgEnd = lpScan;
+ break;
+ case '\"':
+ lpScan++;
+ fQuoted = !fQuoted;
+ break;
+ case '\0':
+ lpArgEnd = lpScan;
+ break;
+ default:
+ lpScan++;
+ break;
+ }
+ } while( *lpScan && !lpArgEnd );
+
+ return lpScan;
+}
+
+
+IMPLEMENT_THUNK( shell32, WINDOWS, LPWSTR *, WINAPI, CommandLineToArgvW, ( LPCWSTR lpCmdLineW, int *pNumArgs ) )
+{
+ LPWSTR *lpArgvW = NULL;
+
+
+ if ( !lpCmdLineW || !*lpCmdLineW )
+ {
+ CHAR szFileName[MAX_PATH];
+
+ DWORD dwResult = GetModuleFileNameA( NULL, szFileName, MAX_PATH );
+
+ if ( dwResult && dwResult < MAX_PATH )
+ {
+ int cchNeeded = MultiByteToWideChar( CP_ACP, 0, szFileName, -1, NULL, 0 );
+
+ lpArgvW = (LPWSTR *)GlobalAlloc( 0, cchNeeded * sizeof(WCHAR) + sizeof(LPWSTR) );
+
+ if ( lpArgvW )
+ {
+ lpArgvW[0] = (LPWSTR)(lpArgvW + 1);
+
+ MultiByteToWideChar( CP_ACP, 0, szFileName, -1, lpArgvW[0], cchNeeded );
+ *pNumArgs = 1;
+ }
+ else
+ SetLastError( ERROR_OUTOFMEMORY );
+ }
+ }
+ else
+ {
+ LPCWSTR lpScan = lpCmdLineW;
+ int nTokens = 0;
+ int cchNeeded = 0;
+
+ // Count arguments and required size
+
+ while ( *lpScan )
+ {
+ lpScan = SkipBlanks( lpScan );
+ if ( *lpScan )
+ {
+ LPCWSTR lpArgEnd = SkipArgument( lpScan );
+
+ nTokens++;
+ cchNeeded += lpArgEnd - lpScan + 1;
+ lpScan = lpArgEnd;
+ }
+ }
+
+ // Allocate space for one additional NULL pointer to terminate list
+
+ lpArgvW = (LPWSTR *)GlobalAlloc( 0, sizeof(LPWSTR) * (nTokens + 1) + sizeof(WCHAR) * cchNeeded );
+
+ if ( lpArgvW )
+ {
+ // Collect arguments
+
+ LPWSTR lpDestination = (LPWSTR)&lpArgvW[nTokens + 1];
+
+ lpScan = lpCmdLineW;
+ nTokens = 0;
+
+ while ( *lpScan )
+ {
+ lpScan = SkipBlanks( lpScan );
+ if ( *lpScan )
+ {
+ LPCWSTR lpArgEnd = SkipArgument( lpScan );
+
+ lpArgvW[nTokens++] = lpDestination;
+
+ while ( lpScan < lpArgEnd )
+ {
+ if ( '\"' != *lpScan )
+ *lpDestination++ = *lpScan;
+
+ lpScan++;
+ }
+ *lpDestination++ = 0;
+ }
+ }
+
+ lpArgvW[nTokens] = NULL;
+
+ *pNumArgs = nTokens;
+ }
+ else
+ SetLastError( ERROR_OUTOFMEMORY );
+
+ }
+
+ return lpArgvW;
+}
diff --git a/sal/systools/win32/uwinapi/CopyFileExA.cpp b/sal/systools/win32/uwinapi/CopyFileExA.cpp
new file mode 100644
index 000000000..e3dbee7fb
--- /dev/null
+++ b/sal/systools/win32/uwinapi/CopyFileExA.cpp
@@ -0,0 +1,138 @@
+#define _UWINAPI_
+#define _WIN32_WINNT 0x0400
+#include "uwinapi.h"
+
+#define BUFSIZE 16384
+
+static DWORD CALLBACK DefCopyProgressRoutine(
+ LARGE_INTEGER TotalFileSize, // total file size, in bytes
+ LARGE_INTEGER TotalBytesTransferred,
+ // total number of bytes transferred
+ LARGE_INTEGER StreamSize, // total number of bytes for this stream
+ LARGE_INTEGER StreamBytesTransferred,
+ // total number of bytes transferred for
+ // this stream
+ DWORD dwStreamNumber, // the current stream
+ DWORD dwCallbackReason, // reason for callback
+ HANDLE hSourceFile, // handle to the source file
+ HANDLE hDestinationFile, // handle to the destination file
+ LPVOID lpData // passed by CopyFileEx
+)
+{
+ return PROGRESS_CONTINUE;
+}
+
+
+IMPLEMENT_THUNK( kernel32, WINDOWS, BOOL, WINAPI, CopyFileExA, ( LPCSTR lpExistingFileNameA, LPCSTR lpNewFileNameA, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, LPBOOL pbCancel, DWORD dwCopyFlags ) )
+{
+ BOOL fSuccess = FALSE; // Assume failure
+
+ HANDLE hSourceFile = CreateFileA(
+ lpExistingFileNameA,
+ GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ 0,
+ NULL
+ );
+
+ if ( IsValidHandle(hSourceFile) )
+ {
+ LARGE_INTEGER FileSize, BytesTransferred;
+ HANDLE hTargetFile = NULL;
+
+ SetLastError( ERROR_SUCCESS );
+ FileSize.LowPart = GetFileSize( hSourceFile, (LPDWORD)&FileSize.HighPart );
+ BytesTransferred.QuadPart = 0;
+
+ if ( (DWORD)-1 != FileSize.LowPart || ERROR_SUCCESS == GetLastError() )
+ hTargetFile = CreateFileA(
+ lpNewFileNameA,
+ GENERIC_WRITE,
+ 0,
+ NULL,
+ (dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) ? CREATE_NEW : CREATE_ALWAYS,
+ 0,
+ NULL
+ );
+
+ if ( IsValidHandle(hTargetFile) )
+ {
+ DWORD dwProgressResult = PROGRESS_CONTINUE;
+
+ fSuccess = SetEndOfFile( hTargetFile );
+
+ if ( fSuccess )
+ {
+ if ( !lpProgressRoutine )
+ lpProgressRoutine = DefCopyProgressRoutine;
+
+ dwProgressResult = lpProgressRoutine(
+ FileSize,
+ BytesTransferred,
+ FileSize,
+ BytesTransferred,
+ 1,
+ CALLBACK_STREAM_SWITCH,
+ hSourceFile,
+ hTargetFile,
+ lpData
+ );
+
+ // Suppress further notifications
+
+ if ( PROGRESS_QUIET == dwProgressResult )
+ {
+ lpProgressRoutine = DefCopyProgressRoutine;
+ dwProgressResult = PROGRESS_CONTINUE;
+ }
+ }
+
+ while ( fSuccess && PROGRESS_CONTINUE == dwProgressResult )
+ {
+ BYTE buffer[BUFSIZE];
+ DWORD dwBytesRead, dwBytesWritten;
+
+ fSuccess = ReadFile( hSourceFile, buffer, BUFSIZE, &dwBytesRead, NULL );
+
+ if ( !dwBytesRead ) break;
+
+ if ( fSuccess )
+ fSuccess = WriteFile( hTargetFile, buffer, dwBytesRead, &dwBytesWritten, NULL );
+
+ if ( fSuccess )
+ {
+ BytesTransferred.QuadPart += (LONGLONG)dwBytesWritten;
+
+ if ( pbCancel && *pbCancel )
+ dwProgressResult = PROGRESS_CANCEL;
+ else
+ dwProgressResult = lpProgressRoutine(
+ FileSize,
+ BytesTransferred,
+ FileSize,
+ BytesTransferred,
+ 1,
+ CALLBACK_CHUNK_FINISHED,
+ hSourceFile,
+ hTargetFile,
+ lpData
+ );
+
+ }
+
+ }
+
+ CloseHandle( hTargetFile );
+
+ if ( PROGRESS_CANCEL == dwProgressResult )
+ DeleteFileA( lpNewFileNameA );
+ }
+
+
+ CloseHandle( hSourceFile );
+ }
+
+ return fSuccess;
+}
diff --git a/sal/systools/win32/uwinapi/CopyFileExW.cpp b/sal/systools/win32/uwinapi/CopyFileExW.cpp
new file mode 100644
index 000000000..605ba621a
--- /dev/null
+++ b/sal/systools/win32/uwinapi/CopyFileExW.cpp
@@ -0,0 +1,11 @@
+#define _UWINAPI_
+#define _WIN32_WINNT 0x0400
+#include "uwinapi.h"
+
+IMPLEMENT_THUNK( kernel32, WINDOWS, BOOL, WINAPI, CopyFileExW, ( LPCWSTR lpExistingFileNameW, LPCWSTR lpNewFileNameW, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, LPBOOL pbCancel, DWORD dwCopyFlags ) )
+{
+ AUTO_WSTR2STR( lpExistingFileName );
+ AUTO_WSTR2STR( lpNewFileName );
+
+ return CopyFileExA( lpExistingFileNameA, lpNewFileNameA, lpProgressRoutine, lpData, pbCancel, dwCopyFlags );
+}
diff --git a/sal/systools/win32/uwinapi/DrawStateW.cpp b/sal/systools/win32/uwinapi/DrawStateW.cpp
new file mode 100644
index 000000000..a25f95576
--- /dev/null
+++ b/sal/systools/win32/uwinapi/DrawStateW.cpp
@@ -0,0 +1,48 @@
+#define _UWINAPI_
+#include "uwinapi.h"
+
+IMPLEMENT_THUNK( user32, WINDOWS, BOOL, WINAPI, DrawStateW,
+(
+ HDC hdc, // handle to device context
+ HBRUSH hbr, // handle to brush
+ DRAWSTATEPROC lpOutputFunc, // pointer to callback function
+ LPARAM lData, // image information
+ WPARAM wData, // more image information
+ int x, // horizontal location of image
+ int y, // vertical location of image
+ int cx, // width of image
+ int cy, // height of image
+ UINT fuFlags // image type and state
+
+))
+{
+ switch ( fuFlags & 0x000F )
+ {
+ case DST_TEXT:
+ case DST_PREFIXTEXT:
+ {
+ LPSTR lpTextA = NULL;
+
+ if ( lData )
+ {
+ int cchWideChar = wData ? wData : -1;
+ int cchNeeded = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lData, cchWideChar, NULL, 0, NULL, NULL );
+
+ lpTextA = (LPSTR)_alloca( cchNeeded * sizeof(CHAR) );
+
+ if ( !lpTextA )
+ {
+ SetLastError( ERROR_OUTOFMEMORY );
+ return FALSE;
+ }
+
+ WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lData, cchWideChar, lpTextA, cchNeeded, NULL, NULL );
+
+ }
+
+ return DrawStateA( hdc, hbr, lpOutputFunc, (LPARAM)lpTextA, wData, x, y, cx, cy, fuFlags );
+ }
+ default:
+ return DrawStateA( hdc, hbr, lpOutputFunc, lData, wData, x, y, cx, cy, fuFlags );
+ }
+}
diff --git a/sal/systools/win32/uwinapi/GetLogicalDriveStringsW.cpp b/sal/systools/win32/uwinapi/GetLogicalDriveStringsW.cpp
new file mode 100644
index 000000000..ea01953be
--- /dev/null
+++ b/sal/systools/win32/uwinapi/GetLogicalDriveStringsW.cpp
@@ -0,0 +1,15 @@
+#define _UWINAPI_
+#include "uwinapi.h"
+
+IMPLEMENT_THUNK( kernel32, WINDOWS, DWORD, WINAPI, GetLogicalDriveStringsW, ( DWORD cchBuffer, LPWSTR lpBufferW ) )
+{
+ AUTO_STR( lpBuffer, cchBuffer );
+
+ DWORD dwResult = GetLogicalDriveStringsA( cchBuffer, lpBufferA );
+
+
+ if ( dwResult && dwResult < cchBuffer )
+ STRBUF2WSTR( lpBuffer, dwResult + 1, cchBuffer );
+
+ return dwResult;
+}
diff --git a/sal/systools/win32/uwinapi/GetLongPathName.cpp b/sal/systools/win32/uwinapi/GetLongPathName.cpp
new file mode 100644
index 000000000..2460bf34a
--- /dev/null
+++ b/sal/systools/win32/uwinapi/GetLongPathName.cpp
@@ -0,0 +1,86 @@
+
+{
+ DWORD dwResult = 0; // Assume failure
+
+ if ( IsBadStringPtr( lpShortPath, MAX_PATH ) )
+ {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return dwResult;
+ }
+
+ // Assume a not existing buffer means a bufsize of zero
+ if ( !lpLongPath )
+ cchBuffer = 0;
+
+ if ( lstrlen( lpShortPath ) == 2 && lpShortPath[1] == ':' )
+ {
+ lstrcpy( lpLongPath, lpShortPath );
+ dwResult = lstrlen( lpLongPath );
+ }
+ else
+ {
+ HANDLE hFind;
+ WIN32_FIND_DATA aFindFileData;
+
+ if ( lpShortPath[lstrlen(lpShortPath)-1] == '\\' )
+ {
+ TCHAR szFilePath[MAX_PATH];
+
+ lstrcpy( szFilePath, lpShortPath );
+ lstrcat( szFilePath, TEXT("*.*") );
+ hFind = FindFirstFile( szFilePath, &aFindFileData );;
+ aFindFileData.cFileName[0] = 0;
+ }
+ else
+ {
+ hFind = FindFirstFile( lpShortPath, &aFindFileData );
+ if ( !IsValidHandle( hFind ) )
+ {
+ TCHAR szFilePath[MAX_PATH];
+
+ lstrcpy( szFilePath, lpShortPath );
+ lstrcat( szFilePath, TEXT("\\*.*") );
+ hFind = FindFirstFile( szFilePath, &aFindFileData );;
+ aFindFileData.cFileName[0] = 0;
+ }
+ }
+
+ if ( IsValidHandle( hFind ) )
+ {
+ FindClose( hFind );
+
+ LPCTSTR lpLastSlash = lstrrchr( lpShortPath, '\\' );
+
+ if ( lpLastSlash )
+ {
+ int nParentLen = lpLastSlash - lpShortPath;
+ LPTSTR lpParentPath = (LPTSTR)_alloca( (nParentLen + 1) * sizeof(TCHAR) );
+
+ CopyMemory( lpParentPath, lpShortPath, nParentLen * sizeof(TCHAR) );
+ lpParentPath[nParentLen] = 0;
+
+ dwResult = GetLongPathName( lpParentPath, lpLongPath, cchBuffer );
+
+ if ( !dwResult )
+ lstrcpy( lpLongPath, lpParentPath );
+ }
+ else
+ {
+ lstrcpy( lpLongPath, lpShortPath );
+ dwResult = lstrlen( lpLongPath );
+ }
+
+ if ( dwResult < cchBuffer )
+ {
+ lstrcat( lpLongPath, TEXT("\\") );
+ lstrcat( lpLongPath, aFindFileData.cFileName );
+ dwResult = lstrlen( lpLongPath );
+ }
+ else
+ dwResult += lstrlen( aFindFileData.cFileName ) + 1;
+ }
+ }
+
+ return dwResult;
+}
+
diff --git a/sal/systools/win32/uwinapi/GetLongPathNameA.cpp b/sal/systools/win32/uwinapi/GetLongPathNameA.cpp
new file mode 100644
index 000000000..244825d17
--- /dev/null
+++ b/sal/systools/win32/uwinapi/GetLongPathNameA.cpp
@@ -0,0 +1,5 @@
+#define _UWINAPI_
+#include "uwinapi.h"
+
+IMPLEMENT_THUNK( kernel32, WINDOWS, DWORD, WINAPI, GetLongPathNameA, ( LPCTSTR lpShortPath, LPTSTR lpLongPath, DWORD cchBuffer ) )
+#include "GetLongPathName.cpp" \ No newline at end of file
diff --git a/sal/systools/win32/uwinapi/GetLongPathNameW.cpp b/sal/systools/win32/uwinapi/GetLongPathNameW.cpp
new file mode 100644
index 000000000..63933723b
--- /dev/null
+++ b/sal/systools/win32/uwinapi/GetLongPathNameW.cpp
@@ -0,0 +1,37 @@
+#define _UWINAPI_
+#define UNICODE
+#include "uwinapi.h"
+
+EXTERN_C DWORD WINAPI GetLongPathNameW_NT( LPCWSTR lpShortPath, LPWSTR lpLongPath, DWORD cchBuffer )
+#include "GetLongPathName.cpp"
+
+EXTERN_C DWORD WINAPI GetLongPathNameW_WINDOWS( LPCWSTR lpShortPathW, LPWSTR lpLongPathW, DWORD cchBuffer )
+{
+ AUTO_WSTR2STR( lpShortPath );
+ AUTO_STR( lpLongPath, cchBuffer );
+
+ DWORD dwResult = GetLongPathNameA( lpShortPathA, lpLongPathA, cchBuffer );
+
+ if ( dwResult && dwResult < cchBuffer )
+ STR2WSTR( lpLongPath, cchBuffer );
+
+ return dwResult;
+}
+
+
+EXTERN_C void WINAPI ResolveThunk_GetLongPathNameW( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName )
+{
+ if ( (LONG)GetVersion < 0 )
+ *lppfn = (FARPROC)GetLongPathNameW_WINDOWS;
+ else
+ {
+ FARPROC lpfnResult = GetProcAddress( LoadLibraryA( lpLibFileName ), lpFuncName );
+ if ( !lpfnResult )
+ lpfnResult = (FARPROC)GetLongPathNameW_NT;
+
+ *lppfn = lpfnResult;
+ }
+}
+
+
+DEFINE_CUSTOM_THUNK( kernel32, GetLongPathNameW, DWORD, WINAPI, GetLongPathNameW, ( LPCWSTR lpShortPathW, LPWSTR lpLongPathW, DWORD cchBuffer ) );
diff --git a/sal/systools/win32/uwinapi/MoveFileExA.cpp b/sal/systools/win32/uwinapi/MoveFileExA.cpp
new file mode 100644
index 000000000..2b5423f46
--- /dev/null
+++ b/sal/systools/win32/uwinapi/MoveFileExA.cpp
@@ -0,0 +1,71 @@
+#define _UWINAPI_
+#include "uwinapi.h"
+
+#define WININIT_FILENAME "wininit.ini"
+#define RENAME_SECTION "rename"
+
+IMPLEMENT_THUNK( kernel32, WINDOWS, BOOL, WINAPI, MoveFileExA, ( LPCSTR lpExistingFileNameA, LPCSTR lpNewFileNameA, DWORD dwFlags ) )
+{
+ BOOL fSuccess = FALSE; // assume failure
+
+ // Windows 9x has a special mechanism to move files after reboot
+
+ if ( dwFlags & MOVEFILE_DELAY_UNTIL_REBOOT )
+ {
+ CHAR szExistingFileNameA[MAX_PATH];
+ CHAR szNewFileNameA[MAX_PATH] = "NUL";
+
+ // Path names in WININIT.INI must be in short path name form
+
+ if (
+ GetShortPathNameA( lpExistingFileNameA, szExistingFileNameA, MAX_PATH ) &&
+ (!lpNewFileNameA || GetShortPathNameA( lpNewFileNameA, szNewFileNameA, MAX_PATH ))
+ )
+ {
+ CHAR szBuffer[32767]; // The buffer size must not exceed 32K
+ DWORD dwBufLen = GetPrivateProfileSectionA( RENAME_SECTION, szBuffer, bufsizeof(szBuffer), WININIT_FILENAME );
+
+ CHAR szRename[MAX_PATH]; // This is enough for at most to times 67 chracters
+ lstrcpyA( szRename, szNewFileNameA );
+ lstrcatA( szRename, "=" );
+ lstrcatA( szRename, szExistingFileNameA );
+ size_t lnRename = lstrlenA(szRename);
+
+ if ( dwBufLen + lnRename + 2 <= bufsizeof(szBuffer) )
+ {
+ CopyMemory( &szBuffer[dwBufLen], szRename, lnRename );
+ szBuffer[dwBufLen + lnRename ] = 0;
+ szBuffer[dwBufLen + lnRename + 1 ] = 0;
+
+ fSuccess = WritePrivateProfileSectionA( RENAME_SECTION, szBuffer, WININIT_FILENAME );
+ }
+ else
+ SetLastError( ERROR_BUFFER_OVERFLOW );
+ }
+ }
+ else
+ {
+
+ fSuccess = MoveFileA( lpExistingFileNameA, lpNewFileNameA );
+
+ if ( !fSuccess && 0 != (dwFlags & (MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) )
+ {
+ BOOL bFailIfExist = 0 == (dwFlags & MOVEFILE_REPLACE_EXISTING);
+
+ fSuccess = CopyFileA( lpExistingFileNameA, lpNewFileNameA, bFailIfExist );
+
+ // In case of successfull copy do not return FALSE if delete fails.
+ // Error detection is done by GetLastError()
+
+ if ( fSuccess )
+ {
+ SetLastError( NO_ERROR );
+ DeleteFileA( lpExistingFileNameA );
+ }
+ }
+
+ }
+
+ return fSuccess;
+}
+
diff --git a/sal/systools/win32/uwinapi/MoveFileExW.cpp b/sal/systools/win32/uwinapi/MoveFileExW.cpp
new file mode 100644
index 000000000..aa2d924c8
--- /dev/null
+++ b/sal/systools/win32/uwinapi/MoveFileExW.cpp
@@ -0,0 +1,12 @@
+#define _UWINAPI_
+#include "uwinapi.h"
+
+IMPLEMENT_THUNK( kernel32, WINDOWS, BOOL, WINAPI, MoveFileExW, ( LPCWSTR lpExistingFileNameW, LPCWSTR lpNewFileNameW, DWORD dwFlags ) )
+{
+ AUTO_WSTR2STR( lpExistingFileName );
+ AUTO_WSTR2STR( lpNewFileName );
+
+ return MoveFileExA( lpExistingFileNameA, lpNewFileNameA, dwFlags );
+}
+
+
diff --git a/sal/systools/win32/uwinapi/ResolveThunk.cpp b/sal/systools/win32/uwinapi/ResolveThunk.cpp
new file mode 100644
index 000000000..7c63dfbb7
--- /dev/null
+++ b/sal/systools/win32/uwinapi/ResolveThunk.cpp
@@ -0,0 +1,38 @@
+#define _UWINAPI_
+#include "uwinapi.h"
+
+
+EXTERN_C void WINAPI ResolveThunk_WINDOWS( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure )
+{
+ FARPROC lpfnResult = (LONG)GetVersion() < 0 ? lpfnEmulate : GetProcAddress( LoadLibraryA( lpLibFileName ), lpFuncName );
+
+ if ( !lpfnResult )
+ lpfnResult = lpfnEmulate;
+
+ if ( !lpfnResult )
+ lpfnResult = lpfnFailure;
+
+ *lppfn = lpfnResult;
+}
+
+
+EXTERN_C void WINAPI ResolveThunk_TRYLOAD( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure )
+{
+ FARPROC lpfnResult = GetProcAddress( LoadLibraryA( lpLibFileName ), lpFuncName );
+
+ if ( !lpfnResult )
+ lpfnResult = lpfnEmulate;
+
+ if ( !lpfnResult )
+ lpfnResult = lpfnFailure;
+
+ *lppfn = lpfnResult;
+}
+
+
+EXTERN_C void WINAPI ResolveThunk_ALLWAYS( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure )
+{
+ *lppfn = lpfnEmulate ? lpfnEmulate : lpfnFailure;
+}
+
+
diff --git a/sal/systools/win32/uwinapi/SHILCreateFromPathW.cpp b/sal/systools/win32/uwinapi/SHILCreateFromPathW.cpp
new file mode 100644
index 000000000..aa2c489a0
--- /dev/null
+++ b/sal/systools/win32/uwinapi/SHILCreateFromPathW.cpp
@@ -0,0 +1,32 @@
+#include "uwinapi.h"
+
+EXTERN_C LPITEMIDLIST WINAPI SHSimpleIDListFromPathW_Failure( LPCWSTR lpPathW )
+{
+ SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
+ return NULL;
+}
+
+EXTERN_C LPITEMIDLIST WINAPI SHSimpleIDListFromPathW_WINDOWS( LPCWSTR lpPathW )
+{
+ AUTO_WSTR2STR( lpPath );
+
+ return SHSimpleIDListFromPathA( lpPathA );
+}
+
+
+EXTERN_C void WINAPI ResolveThunk_SHSimpleIDListFromPathW( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName )
+{
+ if ( (LONG)GetVersion < 0 )
+ *lppfn = (FARPROC)SHSimpleIDListFromPathW_WINDOWS;
+ else
+ {
+ FARPROC lpfnResult = GetProcAddress( LoadLibraryA( lpLibFileName ), MAKEINTRESOURCE(162) );
+ if ( !lpfnResult )
+ lpfnResult = (FARPROC)SHSimpleIDListFromPathW_Failure;
+
+ *lppfn = lpfnResult;
+ }
+}
+
+
+DEFINE_CUSTOM_THUNK( kernel32, GetLongPathNameW, DWORD, WINAPI, GetLongPathNameW, ( LPCWSTR lpShortPathW, LPWSTR lpLongPathW, DWORD cchBuffer ) );
diff --git a/sal/systools/win32/uwinapi/Uwinapi.def b/sal/systools/win32/uwinapi/Uwinapi.def
new file mode 100644
index 000000000..58893d5a5
--- /dev/null
+++ b/sal/systools/win32/uwinapi/Uwinapi.def
@@ -0,0 +1,22 @@
+EXPORTS
+ CommandLineToArgvW
+ CopyFileW
+ CopyFileExW
+ CopyFileExA
+ DeleteFileW
+ DrawStateW
+ GetLogicalDriveStringsW
+ GetLongPathNameA
+ GetLongPathNameW
+ LoadLibraryExW
+ LoadLibraryW
+ MoveFileExA
+ MoveFileExW
+ MoveFileW
+ GetVersion
+ DllGetVersion
+ lstrrchrA
+ lstrrchrW
+ lstrchrA
+ lstrchrW
+
diff --git a/sal/systools/win32/uwinapi/Uwinapi.h b/sal/systools/win32/uwinapi/Uwinapi.h
new file mode 100644
index 000000000..eb2e6bfc4
--- /dev/null
+++ b/sal/systools/win32/uwinapi/Uwinapi.h
@@ -0,0 +1,137 @@
+#pragma once
+
+#ifdef _UWINAPI_
+#define _KERNEL32_
+#define _USER32_
+#define _SHELL32_
+#endif
+
+#include <windows.h>
+#include <malloc.h>
+
+#ifndef _UWINAPI_
+EXTERN_C WINBASEAPI DWORD UWINAPI_dwFakedVersion;
+#endif
+
+EXTERN_C WINBASEAPI DWORD SetVersion( DWORD dwVersion );
+
+/* Version macros */
+
+#define MAKE_VER_WIN32( major, minor, build, isWindows ) \
+((DWORD)MAKELONG( MAKEWORD( major, minor ), (build) | ( isWindows ? 0x8000 : 0 ) ))
+
+#define MAKE_VER_WIN32_NT( major, minor, build ) \
+ MAKE_VER_WIN32( major, minor, build, FALSE )
+
+#define MAKE_VER_WIN32_WINDOWS( major, minor, build ) \
+ MAKE_VER_WIN32( major, minor, build, TRUE )
+
+#define VER_WIN32_WINDOWS_95 MAKE_VER_WIN32_WINDOWS( 4, 0, 0 )
+#define VER_WIN32_WINDOWS_98 MAKE_VER_WIN32_WINDOWS( 4, 10, 0 )
+#define VER_WIN32_WINDOWS_ME MAKE_VER_WIN32_WINDOWS( 4, 90, 0 )
+#define VER_WIN32_NT_NT4 MAKE_VER_WIN32_NT( 4, 0, 0 )
+#define VER_WIN32_NT_2000 MAKE_VER_WIN32_NT( 5, 0, 0 )
+#define VER_WIN32_NT_XP MAKE_VER_WIN32_NT( 5, 1, 0 )
+
+
+EXTERN_C WINBASEAPI LPSTR WINAPI lstrchrA( LPCSTR lpString, CHAR c );
+EXTERN_C WINBASEAPI LPWSTR WINAPI lstrchrW( LPCWSTR lpString, WCHAR c );
+EXTERN_C WINBASEAPI LPSTR WINAPI lstrrchrA( LPCSTR lpString, CHAR c );
+EXTERN_C WINBASEAPI LPWSTR WINAPI lstrrchrW( LPCWSTR lpString, WCHAR c );
+
+#ifdef UNICODE
+#define lstrrchr lstrrchrW
+#define lstrchr lstrchrW
+#else
+#define lstrrchr lstrrchrA
+#define lstrchr lstrchrA
+#endif
+
+// macro that calculates the count of elements of a static array
+
+#define bufsizeof(buf) (sizeof(buf) / sizeof((buf)[0]))
+
+
+#define IsValidHandle(Handle) ((DWORD)(Handle) + 1 > 1)
+
+#ifdef __cplusplus
+
+#define _AUTO_WSTR2STR( lpStrA, lpStrW ) \
+LPSTR lpStrA; \
+if ( lpStrW ) \
+{ \
+ int cNeeded = WideCharToMultiByte( CP_ACP, 0, lpStrW, -1, NULL, 0, NULL, NULL ); \
+ lpStrA = (LPSTR)_alloca( cNeeded * sizeof(CHAR) ); \
+ WideCharToMultiByte( CP_ACP, 0, lpStrW, -1, lpStrA, cNeeded, NULL, NULL ); \
+} \
+else \
+ lpStrA = NULL;
+
+
+#define AUTO_WSTR2STR( lpStr ) \
+ _AUTO_WSTR2STR( lpStr##A, lpStr##W )
+
+#define AUTO_STR( lpStr, cchBuffer ) \
+LPSTR lpStr##A = lpStr##W ? (LPSTR)_alloca( (cchBuffer) * sizeof(CHAR) ) : NULL;
+
+#endif // __cplusplus
+
+#define STRBUF2WSTR( lpStr, cchSrcBuffer, cchDestBuffer ) \
+ MultiByteToWideChar( CP_ACP, 0, lpStr##A, cchSrcBuffer, lpStr##W, cchDestBuffer )
+
+#define STR2WSTR( lpStr, cchBuffer ) \
+ STRBUF2WSTR( lpStr, -1, cchBuffer )
+
+#define WSTR2STR( lpStr, cchBuffer ) \
+ WideCharToMultiByte( CP_ACP, 0, lpStr##W, -1, lpStr##A, cchBuffer, NULL, NULL )
+
+EXTERN_C void WINAPI ResolveThunk_WINDOWS( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure );
+EXTERN_C void WINAPI ResolveThunk_TRYLOAD( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure );
+EXTERN_C void WINAPI ResolveThunk_ALLWAYS( FARPROC *lppfn, LPCSTR lpLibFileName, LPCSTR lpFuncName, FARPROC lpfnEmulate, FARPROC lpfnFailure );
+
+
+
+
+#define IMPLEMENT_THUNK( module, resolve, rettype, calltype, func, params ) \
+EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr; \
+EXTERN_C rettype calltype func##_##resolve params; \
+static rettype calltype func##_##Failure params; \
+static _declspec ( naked ) func##_Thunk() \
+{ \
+ ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func, (FARPROC)func##_##resolve, (FARPROC)func##_##Failure ); \
+ _asm jmp [module##_##func##_Ptr] \
+} \
+EXTERN_C _declspec( naked ) rettype calltype func params \
+{ \
+ _asm jmp [module##_##func##_Ptr] \
+} \
+EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk; \
+static rettype calltype func##_##Failure params \
+{ \
+ SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); \
+ return (rettype)0; \
+} \
+EXTERN_C rettype calltype func##_##resolve params
+
+
+
+
+
+
+
+
+
+
+
+#define DEFINE_CUSTOM_THUNK( module, resolve, rettype, calltype, func, params ) \
+EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr; \
+static _declspec ( naked ) func##_Thunk() \
+{ \
+ ResolveThunk_##resolve( &module##_##func##_Ptr, #module ".dll", #func ); \
+ _asm jmp [module##_##func##_Ptr] \
+} \
+EXTERN_C _declspec( naked ) rettype calltype func params \
+{ \
+ _asm jmp [module##_##func##_Ptr] \
+} \
+EXTERN_C _declspec( dllexport ) FARPROC module##_##func##_Ptr = (FARPROC)func##_Thunk;
diff --git a/sal/systools/win32/uwinapi/makefile.mk b/sal/systools/win32/uwinapi/makefile.mk
new file mode 100644
index 000000000..cee1b4684
--- /dev/null
+++ b/sal/systools/win32/uwinapi/makefile.mk
@@ -0,0 +1,121 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1 $
+#
+# last change: $Author: hro $ $Date: 2002-08-14 14:33:18 $
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+PRJNAME=sal
+TARGET=uwinapi
+
+USE_DEFFILE=TRUE
+LIBTARGET=NO
+#USE_LDUMP2=TRUE
+GEN_HID=TRUE
+
+# --- Settings ----------------------------------
+
+.INCLUDE : settings.mk
+
+# --- Targets ----------------------------------
+
+
+.IF "$(GUI)"=="WNT"
+
+SLOFILES=\
+ $(SLO)$/CommandLineToArgvW.obj\
+ $(SLO)$/CopyFileExA.obj\
+ $(SLO)$/CopyFileExW.obj\
+ $(SLO)$/CopyFileW.obj\
+ $(SLO)$/DeleteFileW.obj\
+ $(SLO)$/DrawStateW.obj\
+ $(SLO)$/GetLogicalDriveStringsW.obj\
+ $(SLO)$/GetLongPathNameA.obj\
+ $(SLO)$/GetLongPathNameW.obj\
+ $(SLO)$/GetVersion.obj\
+ $(SLO)$/LoadLibraryExW.obj\
+ $(SLO)$/LoadLibraryW.obj\
+ $(SLO)$/lstrchrA.obj\
+ $(SLO)$/lstrchrW.obj\
+ $(SLO)$/lstrrchrA.obj\
+ $(SLO)$/lstrrchrW.obj\
+ $(SLO)$/MoveFileExA.obj\
+ $(SLO)$/MoveFileExW.obj\
+ $(SLO)$/MoveFileW.obj\
+ $(SLO)$/NTRTL.obj\
+ $(SLO)$/ResolveThunk.obj
+
+SHL1TARGET=$(TARGET)
+SHL1IMPLIB=$(SHL1TARGET)
+SHL1DEF=$(MISC)/$(SHL1TARGET).def
+DEF1NAME=$(SHL1TARGET)
+DEF1EXPORTFILE= $(SHL1TARGET).dxp
+DEF1DEPN=\
+ $(SHL1TARGET).dxp\
+ makefile.mk
+
+#SHL1VERINFO=$(SHL1TARGET).rc
+SHL1OBJS=$(SLOFILES)
+SHL1STDLIBS=\
+ version.lib
+
+.ENDIF
+
+.INCLUDE : target.mk
+
diff --git a/sal/systools/win32/uwinapi/uwinapi.dxp b/sal/systools/win32/uwinapi/uwinapi.dxp
new file mode 100644
index 000000000..be5fef188
--- /dev/null
+++ b/sal/systools/win32/uwinapi/uwinapi.dxp
@@ -0,0 +1,20 @@
+CommandLineToArgvW
+CopyFileW
+CopyFileExW
+CopyFileExA
+DeleteFileW
+DrawStateW
+GetLogicalDriveStringsW
+GetLongPathNameA
+GetLongPathNameW
+LoadLibraryExW
+LoadLibraryW
+MoveFileExA
+MoveFileExW
+MoveFileW
+GetVersion
+DllGetVersion
+lstrrchrA
+lstrrchrW
+lstrchrA
+lstrchrW