2 * Setupapi miscellaneous functions
4 * Copyright 2005 Eric Kohl
5 * Copyright 2007 Hans Leidekker
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
36 #include "wine/debug.h"
38 #include "setupapi_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
42 /* arbitrary limit not related to what native actually uses */
43 #define OEM_INDEX_LIMIT 999
45 /* Handles and critical sections for the SetupLog API */
46 static HANDLE setupact
= INVALID_HANDLE_VALUE
;
47 static HANDLE setuperr
= INVALID_HANDLE_VALUE
;
48 static CRITICAL_SECTION setupapi_cs
;
49 static CRITICAL_SECTION_DEBUG critsect_debug
=
52 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
53 0, 0, { (DWORD_PTR
)(__FILE__
": setupapi_cs") }
55 static CRITICAL_SECTION setupapi_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
57 /**************************************************************************
60 * Frees an allocated memory block from the process heap.
63 * lpMem [I] pointer to memory block which will be freed
68 VOID WINAPI
MyFree(LPVOID lpMem
)
70 HeapFree(GetProcessHeap(), 0, lpMem
);
74 /**************************************************************************
75 * MyMalloc [SETUPAPI.@]
77 * Allocates memory block from the process heap.
80 * dwSize [I] size of the allocated memory block
83 * Success: pointer to allocated memory block
86 LPVOID WINAPI
MyMalloc(DWORD dwSize
)
88 return HeapAlloc(GetProcessHeap(), 0, dwSize
);
92 /**************************************************************************
93 * MyRealloc [SETUPAPI.@]
95 * Changes the size of an allocated memory block or allocates a memory
96 * block from the process heap.
99 * lpSrc [I] pointer to memory block which will be resized
100 * dwSize [I] new size of the memory block
103 * Success: pointer to the resized memory block
107 * If lpSrc is a NULL-pointer, then MyRealloc allocates a memory
108 * block like MyMalloc.
110 LPVOID WINAPI
MyRealloc(LPVOID lpSrc
, DWORD dwSize
)
113 return HeapAlloc(GetProcessHeap(), 0, dwSize
);
115 return HeapReAlloc(GetProcessHeap(), 0, lpSrc
, dwSize
);
119 /**************************************************************************
120 * DuplicateString [SETUPAPI.@]
122 * Duplicates a unicode string.
125 * lpSrc [I] pointer to the unicode string that will be duplicated
128 * Success: pointer to the duplicated unicode string
132 * Call MyFree() to release the duplicated string.
134 LPWSTR WINAPI
DuplicateString(LPCWSTR lpSrc
)
138 lpDst
= MyMalloc((lstrlenW(lpSrc
) + 1) * sizeof(WCHAR
));
142 lstrcpyW(lpDst
, lpSrc
);
148 /**************************************************************************
149 * QueryRegistryValue [SETUPAPI.@]
151 * Retrieves value data from the registry and allocates memory for the
155 * hKey [I] Handle of the key to query
156 * lpValueName [I] Name of value under hkey to query
157 * lpData [O] Destination for the values contents,
158 * lpType [O] Destination for the value type
159 * lpcbData [O] Destination for the size of data
162 * Success: ERROR_SUCCESS
166 * Use MyFree to release the lpData buffer.
168 LONG WINAPI
QueryRegistryValue(HKEY hKey
,
176 TRACE("%p %s %p %p %p\n",
177 hKey
, debugstr_w(lpValueName
), lpData
, lpType
, lpcbData
);
179 /* Get required buffer size */
181 lError
= RegQueryValueExW(hKey
, lpValueName
, 0, lpType
, NULL
, lpcbData
);
182 if (lError
!= ERROR_SUCCESS
)
185 /* Allocate buffer */
186 *lpData
= MyMalloc(*lpcbData
);
188 return ERROR_NOT_ENOUGH_MEMORY
;
190 /* Query registry value */
191 lError
= RegQueryValueExW(hKey
, lpValueName
, 0, lpType
, *lpData
, lpcbData
);
192 if (lError
!= ERROR_SUCCESS
)
199 /**************************************************************************
200 * IsUserAdmin [SETUPAPI.@]
202 * Checks whether the current user is a member of the Administrators group.
211 BOOL WINAPI
IsUserAdmin(VOID
)
214 return IsUserAnAdmin();
218 /**************************************************************************
219 * MultiByteToUnicode [SETUPAPI.@]
221 * Converts a multi-byte string to a Unicode string.
224 * lpMultiByteStr [I] Multi-byte string to be converted
225 * uCodePage [I] Code page
228 * Success: pointer to the converted Unicode string
232 * Use MyFree to release the returned Unicode string.
234 LPWSTR WINAPI
MultiByteToUnicode(LPCSTR lpMultiByteStr
, UINT uCodePage
)
239 nLength
= MultiByteToWideChar(uCodePage
, 0, lpMultiByteStr
,
244 lpUnicodeStr
= MyMalloc(nLength
* sizeof(WCHAR
));
245 if (lpUnicodeStr
== NULL
)
248 if (!MultiByteToWideChar(uCodePage
, 0, lpMultiByteStr
,
249 nLength
, lpUnicodeStr
, nLength
))
251 MyFree(lpUnicodeStr
);
259 /**************************************************************************
260 * UnicodeToMultiByte [SETUPAPI.@]
262 * Converts a Unicode string to a multi-byte string.
265 * lpUnicodeStr [I] Unicode string to be converted
266 * uCodePage [I] Code page
269 * Success: pointer to the converted multi-byte string
273 * Use MyFree to release the returned multi-byte string.
275 LPSTR WINAPI
UnicodeToMultiByte(LPCWSTR lpUnicodeStr
, UINT uCodePage
)
277 LPSTR lpMultiByteStr
;
280 nLength
= WideCharToMultiByte(uCodePage
, 0, lpUnicodeStr
, -1,
281 NULL
, 0, NULL
, NULL
);
285 lpMultiByteStr
= MyMalloc(nLength
);
286 if (lpMultiByteStr
== NULL
)
289 if (!WideCharToMultiByte(uCodePage
, 0, lpUnicodeStr
, -1,
290 lpMultiByteStr
, nLength
, NULL
, NULL
))
292 MyFree(lpMultiByteStr
);
296 return lpMultiByteStr
;
300 /**************************************************************************
301 * DoesUserHavePrivilege [SETUPAPI.@]
303 * Check whether the current user has got a given privilege.
306 * lpPrivilegeName [I] Name of the privilege to be checked
312 BOOL WINAPI
DoesUserHavePrivilege(LPCWSTR lpPrivilegeName
)
316 PTOKEN_PRIVILEGES lpPrivileges
;
319 BOOL bResult
= FALSE
;
321 TRACE("%s\n", debugstr_w(lpPrivilegeName
));
323 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
326 if (!GetTokenInformation(hToken
, TokenPrivileges
, NULL
, 0, &dwSize
))
328 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
335 lpPrivileges
= MyMalloc(dwSize
);
336 if (lpPrivileges
== NULL
)
342 if (!GetTokenInformation(hToken
, TokenPrivileges
, lpPrivileges
, dwSize
, &dwSize
))
344 MyFree(lpPrivileges
);
351 if (!LookupPrivilegeValueW(NULL
, lpPrivilegeName
, &PrivilegeLuid
))
353 MyFree(lpPrivileges
);
357 for (i
= 0; i
< lpPrivileges
->PrivilegeCount
; i
++)
359 if (lpPrivileges
->Privileges
[i
].Luid
.HighPart
== PrivilegeLuid
.HighPart
&&
360 lpPrivileges
->Privileges
[i
].Luid
.LowPart
== PrivilegeLuid
.LowPart
)
366 MyFree(lpPrivileges
);
372 /**************************************************************************
373 * EnablePrivilege [SETUPAPI.@]
375 * Enables or disables one of the current users privileges.
378 * lpPrivilegeName [I] Name of the privilege to be changed
379 * bEnable [I] TRUE: Enables the privilege
380 * FALSE: Disables the privilege
386 BOOL WINAPI
EnablePrivilege(LPCWSTR lpPrivilegeName
, BOOL bEnable
)
388 TOKEN_PRIVILEGES Privileges
;
392 TRACE("%s %s\n", debugstr_w(lpPrivilegeName
), bEnable
? "TRUE" : "FALSE");
394 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
397 Privileges
.PrivilegeCount
= 1;
398 Privileges
.Privileges
[0].Attributes
= (bEnable
) ? SE_PRIVILEGE_ENABLED
: 0;
400 if (!LookupPrivilegeValueW(NULL
, lpPrivilegeName
,
401 &Privileges
.Privileges
[0].Luid
))
407 bResult
= AdjustTokenPrivileges(hToken
, FALSE
, &Privileges
, 0, NULL
, NULL
);
415 /**************************************************************************
416 * DelayedMove [SETUPAPI.@]
418 * Moves a file upon the next reboot.
421 * lpExistingFileName [I] Current file name
422 * lpNewFileName [I] New file name
428 BOOL WINAPI
DelayedMove(LPCWSTR lpExistingFileName
, LPCWSTR lpNewFileName
)
430 return MoveFileExW(lpExistingFileName
, lpNewFileName
,
431 MOVEFILE_REPLACE_EXISTING
| MOVEFILE_DELAY_UNTIL_REBOOT
);
435 /**************************************************************************
436 * FileExists [SETUPAPI.@]
438 * Checks whether a file exists.
441 * lpFileName [I] Name of the file to check
442 * lpNewFileName [O] Optional information about the existing file
448 BOOL WINAPI
FileExists(LPCWSTR lpFileName
, LPWIN32_FIND_DATAW lpFileFindData
)
450 WIN32_FIND_DATAW FindData
;
455 uErrorMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
457 hFind
= FindFirstFileW(lpFileName
, &FindData
);
458 if (hFind
== INVALID_HANDLE_VALUE
)
460 dwError
= GetLastError();
461 SetErrorMode(uErrorMode
);
462 SetLastError(dwError
);
469 *lpFileFindData
= FindData
;
471 SetErrorMode(uErrorMode
);
477 /**************************************************************************
478 * CaptureStringArg [SETUPAPI.@]
480 * Captures a UNICODE string.
483 * lpSrc [I] UNICODE string to be captured
484 * lpDst [O] Pointer to the captured UNICODE string
487 * Success: ERROR_SUCCESS
488 * Failure: ERROR_INVALID_PARAMETER
491 * Call MyFree to release the captured UNICODE string.
493 DWORD WINAPI
CaptureStringArg(LPCWSTR pSrc
, LPWSTR
*pDst
)
496 return ERROR_INVALID_PARAMETER
;
498 *pDst
= DuplicateString(pSrc
);
500 return ERROR_SUCCESS
;
504 /**************************************************************************
505 * CaptureAndConvertAnsiArg [SETUPAPI.@]
507 * Captures an ANSI string and converts it to a UNICODE string.
510 * lpSrc [I] ANSI string to be captured
511 * lpDst [O] Pointer to the captured UNICODE string
514 * Success: ERROR_SUCCESS
515 * Failure: ERROR_INVALID_PARAMETER
518 * Call MyFree to release the captured UNICODE string.
520 DWORD WINAPI
CaptureAndConvertAnsiArg(LPCSTR pSrc
, LPWSTR
*pDst
)
523 return ERROR_INVALID_PARAMETER
;
525 *pDst
= MultiByteToUnicode(pSrc
, CP_ACP
);
527 return ERROR_SUCCESS
;
531 /**************************************************************************
532 * OpenAndMapFileForRead [SETUPAPI.@]
534 * Open and map a file to a buffer.
537 * lpFileName [I] Name of the file to be opened
538 * lpSize [O] Pointer to the file size
539 * lpFile [0] Pointer to the file handle
540 * lpMapping [0] Pointer to the mapping handle
541 * lpBuffer [0] Pointer to the file buffer
544 * Success: ERROR_SUCCESS
548 * Call UnmapAndCloseFile to release the file.
550 DWORD WINAPI
OpenAndMapFileForRead(LPCWSTR lpFileName
,
558 TRACE("%s %p %p %p %p\n",
559 debugstr_w(lpFileName
), lpSize
, lpFile
, lpMapping
, lpBuffer
);
561 *lpFile
= CreateFileW(lpFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
562 OPEN_EXISTING
, 0, NULL
);
563 if (*lpFile
== INVALID_HANDLE_VALUE
)
564 return GetLastError();
566 *lpSize
= GetFileSize(*lpFile
, NULL
);
567 if (*lpSize
== INVALID_FILE_SIZE
)
569 dwError
= GetLastError();
570 CloseHandle(*lpFile
);
574 *lpMapping
= CreateFileMappingW(*lpFile
, NULL
, PAGE_READONLY
, 0,
576 if (*lpMapping
== NULL
)
578 dwError
= GetLastError();
579 CloseHandle(*lpFile
);
583 *lpBuffer
= MapViewOfFile(*lpMapping
, FILE_MAP_READ
, 0, 0, *lpSize
);
584 if (*lpBuffer
== NULL
)
586 dwError
= GetLastError();
587 CloseHandle(*lpMapping
);
588 CloseHandle(*lpFile
);
592 return ERROR_SUCCESS
;
596 /**************************************************************************
597 * UnmapAndCloseFile [SETUPAPI.@]
599 * Unmap and close a mapped file.
602 * hFile [I] Handle to the file
603 * hMapping [I] Handle to the file mapping
604 * lpBuffer [I] Pointer to the file buffer
610 BOOL WINAPI
UnmapAndCloseFile(HANDLE hFile
, HANDLE hMapping
, LPVOID lpBuffer
)
613 hFile
, hMapping
, lpBuffer
);
615 if (!UnmapViewOfFile(lpBuffer
))
618 if (!CloseHandle(hMapping
))
621 if (!CloseHandle(hFile
))
628 /**************************************************************************
629 * StampFileSecurity [SETUPAPI.@]
631 * Assign a new security descriptor to the given file.
634 * lpFileName [I] Name of the file
635 * pSecurityDescriptor [I] New security descriptor
638 * Success: ERROR_SUCCESS
641 DWORD WINAPI
StampFileSecurity(LPCWSTR lpFileName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
)
643 TRACE("%s %p\n", debugstr_w(lpFileName
), pSecurityDescriptor
);
645 if (!SetFileSecurityW(lpFileName
, OWNER_SECURITY_INFORMATION
|
646 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
,
647 pSecurityDescriptor
))
648 return GetLastError();
650 return ERROR_SUCCESS
;
654 /**************************************************************************
655 * TakeOwnershipOfFile [SETUPAPI.@]
657 * Takes the ownership of the given file.
660 * lpFileName [I] Name of the file
663 * Success: ERROR_SUCCESS
666 DWORD WINAPI
TakeOwnershipOfFile(LPCWSTR lpFileName
)
668 SECURITY_DESCRIPTOR SecDesc
;
669 HANDLE hToken
= NULL
;
670 PTOKEN_OWNER pOwner
= NULL
;
674 TRACE("%s\n", debugstr_w(lpFileName
));
676 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
677 return GetLastError();
679 if (!GetTokenInformation(hToken
, TokenOwner
, NULL
, 0, &dwSize
))
684 pOwner
= MyMalloc(dwSize
);
688 return ERROR_NOT_ENOUGH_MEMORY
;
691 if (!GetTokenInformation(hToken
, TokenOwner
, pOwner
, dwSize
, &dwSize
))
696 if (!InitializeSecurityDescriptor(&SecDesc
, SECURITY_DESCRIPTOR_REVISION
))
701 if (!SetSecurityDescriptorOwner(&SecDesc
, pOwner
->Owner
, FALSE
))
706 if (!SetFileSecurityW(lpFileName
, OWNER_SECURITY_INFORMATION
, &SecDesc
))
714 return ERROR_SUCCESS
;
717 dwError
= GetLastError();
728 /**************************************************************************
729 * RetreiveFileSecurity [SETUPAPI.@]
731 * Retrieve the security descriptor that is associated with the given file.
734 * lpFileName [I] Name of the file
737 * Success: ERROR_SUCCESS
740 DWORD WINAPI
RetreiveFileSecurity(LPCWSTR lpFileName
,
741 PSECURITY_DESCRIPTOR
*pSecurityDescriptor
)
743 PSECURITY_DESCRIPTOR SecDesc
;
744 DWORD dwSize
= 0x100;
747 SecDesc
= MyMalloc(dwSize
);
749 return ERROR_NOT_ENOUGH_MEMORY
;
751 if (GetFileSecurityW(lpFileName
, OWNER_SECURITY_INFORMATION
|
752 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
,
753 SecDesc
, dwSize
, &dwSize
))
755 *pSecurityDescriptor
= SecDesc
;
756 return ERROR_SUCCESS
;
759 dwError
= GetLastError();
760 if (dwError
!= ERROR_INSUFFICIENT_BUFFER
)
766 SecDesc
= MyRealloc(SecDesc
, dwSize
);
768 return ERROR_NOT_ENOUGH_MEMORY
;
770 if (GetFileSecurityW(lpFileName
, OWNER_SECURITY_INFORMATION
|
771 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
,
772 SecDesc
, dwSize
, &dwSize
))
774 *pSecurityDescriptor
= SecDesc
;
775 return ERROR_SUCCESS
;
778 dwError
= GetLastError();
785 static DWORD global_flags
= 0; /* FIXME: what should be in here? */
787 /***********************************************************************
788 * pSetupGetGlobalFlags (SETUPAPI.@)
790 DWORD WINAPI
pSetupGetGlobalFlags(void)
797 /***********************************************************************
798 * pSetupSetGlobalFlags (SETUPAPI.@)
800 void WINAPI
pSetupSetGlobalFlags( DWORD flags
)
802 global_flags
= flags
;
805 /***********************************************************************
806 * CMP_WaitNoPendingInstallEvents (SETUPAPI.@)
808 DWORD WINAPI
CMP_WaitNoPendingInstallEvents( DWORD dwTimeout
)
810 static BOOL warned
= FALSE
;
814 FIXME("%d\n", dwTimeout
);
817 return WAIT_OBJECT_0
;
820 /***********************************************************************
821 * AssertFail (SETUPAPI.@)
823 * Shows an assert fail error messagebox
826 * lpFile [I] file where assert failed
827 * uLine [I] line number in file
828 * lpMessage [I] assert message
831 void WINAPI
AssertFail(LPCSTR lpFile
, UINT uLine
, LPCSTR lpMessage
)
833 FIXME("%s %u %s\n", lpFile
, uLine
, lpMessage
);
836 /***********************************************************************
837 * SetupCopyOEMInfA (SETUPAPI.@)
839 BOOL WINAPI
SetupCopyOEMInfA( PCSTR source
, PCSTR location
,
840 DWORD media_type
, DWORD style
, PSTR dest
,
841 DWORD buffer_size
, PDWORD required_size
, PSTR
*component
)
844 LPWSTR destW
= NULL
, sourceW
= NULL
, locationW
= NULL
;
847 TRACE("%s, %s, %d, %d, %p, %d, %p, %p\n", debugstr_a(source
), debugstr_a(location
),
848 media_type
, style
, dest
, buffer_size
, required_size
, component
);
850 if (dest
&& !(destW
= MyMalloc( buffer_size
* sizeof(WCHAR
) ))) return FALSE
;
851 if (source
&& !(sourceW
= strdupAtoW( source
))) goto done
;
852 if (location
&& !(locationW
= strdupAtoW( location
))) goto done
;
854 ret
= SetupCopyOEMInfW( sourceW
, locationW
, media_type
, style
, destW
, buffer_size
, &size
, NULL
);
856 if (required_size
) *required_size
= size
;
860 if (buffer_size
>= size
)
862 WideCharToMultiByte( CP_ACP
, 0, destW
, -1, dest
, buffer_size
, NULL
, NULL
);
863 if (component
) *component
= strrchr( dest
, '\\' ) + 1;
866 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
871 HeapFree( GetProcessHeap(), 0, sourceW
);
872 HeapFree( GetProcessHeap(), 0, locationW
);
873 if (ret
) SetLastError(ERROR_SUCCESS
);
877 static int compare_files( HANDLE file1
, HANDLE file2
)
884 while( ReadFile(file1
, buffer1
, sizeof(buffer1
), &size1
, NULL
) &&
885 ReadFile(file2
, buffer2
, sizeof(buffer2
), &size2
, NULL
) )
889 return size1
> size2
? 1 : -1;
892 ret
= memcmp( buffer1
, buffer2
, size1
);
900 static BOOL
find_existing_inf(const WCHAR
*source
, WCHAR
*target
)
902 static const WCHAR infW
[] = {'\\','i','n','f','\\',0};
903 static const WCHAR wildcardW
[] = {'*',0};
905 LARGE_INTEGER source_file_size
, dest_file_size
;
906 HANDLE source_file
, dest_file
;
907 WIN32_FIND_DATAW find_data
;
910 source_file
= CreateFileW( source
, FILE_READ_DATA
| FILE_READ_ATTRIBUTES
,
911 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
912 NULL
, OPEN_EXISTING
, 0, NULL
);
913 if (source_file
== INVALID_HANDLE_VALUE
)
916 if (!GetFileSizeEx( source_file
, &source_file_size
))
918 CloseHandle( source_file
);
922 GetWindowsDirectoryW( target
, MAX_PATH
);
923 lstrcatW( target
, infW
);
924 lstrcatW( target
, wildcardW
);
925 if ((find_handle
= FindFirstFileW( target
, &find_data
)) != INVALID_HANDLE_VALUE
)
928 GetWindowsDirectoryW( target
, MAX_PATH
);
929 lstrcatW( target
, infW
);
930 lstrcatW( target
, find_data
.cFileName
);
931 dest_file
= CreateFileW( target
, FILE_READ_DATA
| FILE_READ_ATTRIBUTES
,
932 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
933 NULL
, OPEN_EXISTING
, 0, NULL
);
934 if (dest_file
== INVALID_HANDLE_VALUE
)
937 SetFilePointer( source_file
, 0, NULL
, FILE_BEGIN
);
939 if (GetFileSizeEx( dest_file
, &dest_file_size
)
940 && dest_file_size
.QuadPart
== source_file_size
.QuadPart
941 && !compare_files( source_file
, dest_file
))
943 CloseHandle( dest_file
);
944 CloseHandle( source_file
);
945 FindClose( find_handle
);
948 CloseHandle( dest_file
);
949 } while (FindNextFileW( find_handle
, &find_data
));
951 FindClose( find_handle
);
954 CloseHandle( source_file
);
958 /***********************************************************************
959 * SetupCopyOEMInfW (SETUPAPI.@)
961 BOOL WINAPI
SetupCopyOEMInfW( PCWSTR source
, PCWSTR location
,
962 DWORD media_type
, DWORD style
, PWSTR dest
,
963 DWORD buffer_size
, DWORD
*required_size
, WCHAR
**filepart
)
966 WCHAR target
[MAX_PATH
], catalog_file
[MAX_PATH
], pnf_path
[MAX_PATH
], *p
;
967 static const WCHAR inf
[] = { '\\','i','n','f','\\',0 };
968 static const WCHAR wszVersion
[] = { 'V','e','r','s','i','o','n',0 };
969 static const WCHAR wszCatalogFile
[] = { 'C','a','t','a','l','o','g','F','i','l','e',0 };
975 TRACE("%s, %s, %d, %d, %p, %d, %p, %p\n", debugstr_w(source
), debugstr_w(location
),
976 media_type
, style
, dest
, buffer_size
, required_size
, filepart
);
980 SetLastError(ERROR_INVALID_PARAMETER
);
984 /* check for a relative path */
985 if (!(*source
== '\\' || (*source
&& source
[1] == ':')))
987 SetLastError(ERROR_FILE_NOT_FOUND
);
991 if (find_existing_inf( source
, target
))
993 TRACE("Found existing INF %s.\n", debugstr_w(target
));
994 if (style
& SP_COPY_NOOVERWRITE
)
996 SetLastError( ERROR_FILE_EXISTS
);
1004 GetWindowsDirectoryW( target
, ARRAY_SIZE(target
) );
1005 lstrcatW( target
, inf
);
1006 lstrcatW( target
, wcsrchr( source
, '\\' ) + 1 );
1007 if (GetFileAttributesW( target
) != INVALID_FILE_ATTRIBUTES
)
1009 for (i
= 0; i
< OEM_INDEX_LIMIT
; i
++)
1011 static const WCHAR formatW
[] = {'o','e','m','%','u','.','i','n','f',0};
1013 GetWindowsDirectoryW( target
, ARRAY_SIZE(target
) );
1014 lstrcatW( target
, inf
);
1015 swprintf( target
+ lstrlenW(target
), ARRAY_SIZE(target
) - lstrlenW(target
), formatW
, i
);
1017 if (GetFileAttributesW( target
) == INVALID_FILE_ATTRIBUTES
)
1020 if (i
== OEM_INDEX_LIMIT
)
1022 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
1027 hinf
= SetupOpenInfFileW( source
, NULL
, INF_STYLE_WIN4
, NULL
);
1028 if (hinf
== INVALID_HANDLE_VALUE
) return FALSE
;
1030 if (SetupGetLineTextW( NULL
, hinf
, wszVersion
, wszCatalogFile
, catalog_file
,
1031 ARRAY_SIZE( catalog_file
), NULL
))
1033 WCHAR source_cat
[MAX_PATH
];
1036 GUID msguid
= DRIVER_ACTION_VERIFY
;
1038 SetupCloseInfFile( hinf
);
1040 lstrcpyW( source_cat
, source
);
1041 p
= wcsrchr( source_cat
, '\\' );
1043 else p
= source_cat
;
1044 lstrcpyW( p
, catalog_file
);
1046 TRACE("installing catalog file %s\n", debugstr_w( source_cat
));
1048 if (!CryptCATAdminAcquireContext(&handle
, &msguid
, 0))
1050 ERR("Could not acquire security context\n");
1054 if (!(cat
= CryptCATAdminAddCatalog(handle
, source_cat
, catalog_file
, 0)))
1056 ERR("Could not add catalog\n");
1057 CryptCATAdminReleaseContext(handle
, 0);
1061 CryptCATAdminReleaseCatalogContext(handle
, cat
, 0);
1062 CryptCATAdminReleaseContext(handle
, 0);
1065 SetupCloseInfFile( hinf
);
1067 if (!(ret
= CopyFileW( source
, target
, TRUE
)))
1071 if (style
& SP_COPY_DELETESOURCE
)
1072 DeleteFileW( source
);
1076 wcscpy(pnf_path
, target
);
1077 PathRemoveExtensionW(pnf_path
);
1078 PathAddExtensionW(pnf_path
, L
".pnf");
1079 if ((pnf_file
= _wfopen(pnf_path
, L
"w")))
1081 fputws(PNF_HEADER
, pnf_file
);
1082 fputws(source
, pnf_file
);
1087 size
= lstrlenW( target
) + 1;
1090 if (buffer_size
>= size
)
1092 lstrcpyW( dest
, target
);
1093 if (filepart
) *filepart
= wcsrchr( dest
, '\\' ) + 1;
1097 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1102 if (required_size
) *required_size
= size
;
1103 if (ret
) SetLastError(ERROR_SUCCESS
);
1108 /***********************************************************************
1109 * SetupUninstallOEMInfA (SETUPAPI.@)
1111 BOOL WINAPI
SetupUninstallOEMInfA( PCSTR inf_file
, DWORD flags
, PVOID reserved
)
1114 WCHAR
*inf_fileW
= NULL
;
1116 TRACE("%s, 0x%08x, %p\n", debugstr_a(inf_file
), flags
, reserved
);
1118 if (inf_file
&& !(inf_fileW
= strdupAtoW( inf_file
))) return FALSE
;
1119 ret
= SetupUninstallOEMInfW( inf_fileW
, flags
, reserved
);
1120 HeapFree( GetProcessHeap(), 0, inf_fileW
);
1124 /***********************************************************************
1125 * SetupUninstallOEMInfW (SETUPAPI.@)
1127 BOOL WINAPI
SetupUninstallOEMInfW( PCWSTR inf_file
, DWORD flags
, PVOID reserved
)
1129 static const WCHAR infW
[] = {'\\','i','n','f','\\',0};
1130 WCHAR target
[MAX_PATH
];
1132 TRACE("%s, 0x%08x, %p\n", debugstr_w(inf_file
), flags
, reserved
);
1136 SetLastError(ERROR_INVALID_PARAMETER
);
1140 if (!GetWindowsDirectoryW( target
, ARRAY_SIZE( target
))) return FALSE
;
1142 lstrcatW( target
, infW
);
1143 lstrcatW( target
, inf_file
);
1145 if (flags
& SUOI_FORCEDELETE
)
1146 return DeleteFileW(target
);
1148 FIXME("not deleting %s\n", debugstr_w(target
));
1153 /***********************************************************************
1154 * InstallCatalog (SETUPAPI.@)
1156 DWORD WINAPI
InstallCatalog( LPCSTR catalog
, LPCSTR basename
, LPSTR fullname
)
1158 FIXME("%s, %s, %p\n", debugstr_a(catalog
), debugstr_a(basename
), fullname
);
1162 /***********************************************************************
1163 * pSetupInstallCatalog (SETUPAPI.@)
1165 DWORD WINAPI
pSetupInstallCatalog( LPCWSTR catalog
, LPCWSTR basename
, LPWSTR fullname
)
1170 TRACE ("%s, %s, %p\n", debugstr_w(catalog
), debugstr_w(basename
), fullname
);
1172 if (!CryptCATAdminAcquireContext(&admin
,NULL
,0))
1173 return GetLastError();
1175 if (!(cat
= CryptCATAdminAddCatalog( admin
, (PWSTR
)catalog
, (PWSTR
)basename
, 0 )))
1177 DWORD rc
= GetLastError();
1178 CryptCATAdminReleaseContext(admin
, 0);
1181 CryptCATAdminReleaseCatalogContext(admin
, cat
, 0);
1182 CryptCATAdminReleaseContext(admin
,0);
1185 FIXME("not returning full installed catalog path\n");
1190 static UINT
detect_compression_type( LPCWSTR file
)
1194 UINT type
= FILE_COMPRESSION_NONE
;
1195 static const BYTE LZ_MAGIC
[] = { 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33 };
1196 static const BYTE MSZIP_MAGIC
[] = { 0x4b, 0x57, 0x41, 0x4a };
1197 static const BYTE NTCAB_MAGIC
[] = { 0x4d, 0x53, 0x43, 0x46 };
1200 handle
= CreateFileW( file
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1201 if (handle
== INVALID_HANDLE_VALUE
)
1203 ERR("cannot open file %s\n", debugstr_w(file
));
1204 return FILE_COMPRESSION_NONE
;
1206 if (!ReadFile( handle
, buffer
, sizeof(buffer
), &size
, NULL
) || size
!= sizeof(buffer
))
1208 CloseHandle( handle
);
1209 return FILE_COMPRESSION_NONE
;
1211 if (!memcmp( buffer
, LZ_MAGIC
, sizeof(LZ_MAGIC
) )) type
= FILE_COMPRESSION_WINLZA
;
1212 else if (!memcmp( buffer
, MSZIP_MAGIC
, sizeof(MSZIP_MAGIC
) )) type
= FILE_COMPRESSION_MSZIP
;
1213 else if (!memcmp( buffer
, NTCAB_MAGIC
, sizeof(NTCAB_MAGIC
) )) type
= FILE_COMPRESSION_MSZIP
; /* not a typo */
1215 CloseHandle( handle
);
1219 static BOOL
get_file_size( LPCWSTR file
, DWORD
*size
)
1223 handle
= CreateFileW( file
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1224 if (handle
== INVALID_HANDLE_VALUE
)
1226 ERR("cannot open file %s\n", debugstr_w(file
));
1229 *size
= GetFileSize( handle
, NULL
);
1230 CloseHandle( handle
);
1234 static BOOL
get_file_sizes_none( LPCWSTR source
, DWORD
*source_size
, DWORD
*target_size
)
1238 if (!get_file_size( source
, &size
)) return FALSE
;
1239 if (source_size
) *source_size
= size
;
1240 if (target_size
) *target_size
= size
;
1244 static BOOL
get_file_sizes_lz( LPCWSTR source
, DWORD
*source_size
, DWORD
*target_size
)
1251 if (!get_file_size( source
, &size
)) ret
= FALSE
;
1252 else *source_size
= size
;
1259 if ((file
= LZOpenFileW( (LPWSTR
)source
, &of
, OF_READ
)) < 0)
1261 ERR("cannot open source file for reading\n");
1264 *target_size
= LZSeek( file
, 0, 2 );
1270 static UINT CALLBACK
file_compression_info_callback( PVOID context
, UINT notification
, UINT_PTR param1
, UINT_PTR param2
)
1272 DWORD
*size
= context
;
1273 FILE_IN_CABINET_INFO_W
*info
= (FILE_IN_CABINET_INFO_W
*)param1
;
1275 switch (notification
)
1277 case SPFILENOTIFY_FILEINCABINET
:
1279 *size
= info
->FileSize
;
1282 default: return NO_ERROR
;
1286 static BOOL
get_file_sizes_cab( LPCWSTR source
, DWORD
*source_size
, DWORD
*target_size
)
1293 if (!get_file_size( source
, &size
)) ret
= FALSE
;
1294 else *source_size
= size
;
1298 ret
= SetupIterateCabinetW( source
, 0, file_compression_info_callback
, target_size
);
1303 /***********************************************************************
1304 * SetupGetFileCompressionInfoExA (SETUPAPI.@)
1306 * See SetupGetFileCompressionInfoExW.
1308 BOOL WINAPI
SetupGetFileCompressionInfoExA( PCSTR source
, PSTR name
, DWORD len
, PDWORD required
,
1309 PDWORD source_size
, PDWORD target_size
, PUINT type
)
1312 WCHAR
*nameW
= NULL
, *sourceW
= NULL
;
1316 TRACE("%s, %p, %d, %p, %p, %p, %p\n", debugstr_a(source
), name
, len
, required
,
1317 source_size
, target_size
, type
);
1319 if (!source
|| !(sourceW
= MultiByteToUnicode( source
, CP_ACP
))) return FALSE
;
1323 ret
= SetupGetFileCompressionInfoExW( sourceW
, NULL
, 0, &nb_chars
, NULL
, NULL
, NULL
);
1324 if (!(nameW
= HeapAlloc( GetProcessHeap(), 0, nb_chars
* sizeof(WCHAR
) )))
1330 ret
= SetupGetFileCompressionInfoExW( sourceW
, nameW
, nb_chars
, &nb_chars
, source_size
, target_size
, type
);
1333 if ((nameA
= UnicodeToMultiByte( nameW
, CP_ACP
)))
1335 if (name
&& len
>= nb_chars
) lstrcpyA( name
, nameA
);
1338 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1344 if (required
) *required
= nb_chars
;
1345 HeapFree( GetProcessHeap(), 0, nameW
);
1351 /***********************************************************************
1352 * SetupGetFileCompressionInfoExW (SETUPAPI.@)
1354 * Get compression type and compressed/uncompressed sizes of a given file.
1357 * source [I] File to examine.
1358 * name [O] Actual filename used.
1359 * len [I] Length in characters of 'name' buffer.
1360 * required [O] Number of characters written to 'name'.
1361 * source_size [O] Size of compressed file.
1362 * target_size [O] Size of uncompressed file.
1363 * type [O] Compression type.
1369 BOOL WINAPI
SetupGetFileCompressionInfoExW( PCWSTR source
, PWSTR name
, DWORD len
, PDWORD required
,
1370 PDWORD source_size
, PDWORD target_size
, PUINT type
)
1376 TRACE("%s, %p, %d, %p, %p, %p, %p\n", debugstr_w(source
), name
, len
, required
,
1377 source_size
, target_size
, type
);
1379 if (!source
) return FALSE
;
1381 source_len
= lstrlenW( source
) + 1;
1382 if (required
) *required
= source_len
;
1383 if (name
&& len
>= source_len
)
1385 lstrcpyW( name
, source
);
1390 comp
= detect_compression_type( source
);
1391 if (type
) *type
= comp
;
1395 case FILE_COMPRESSION_MSZIP
:
1396 case FILE_COMPRESSION_NTCAB
: ret
= get_file_sizes_cab( source
, source_size
, target_size
); break;
1397 case FILE_COMPRESSION_NONE
: ret
= get_file_sizes_none( source
, source_size
, target_size
); break;
1398 case FILE_COMPRESSION_WINLZA
: ret
= get_file_sizes_lz( source
, source_size
, target_size
); break;
1404 /***********************************************************************
1405 * SetupGetFileCompressionInfoA (SETUPAPI.@)
1407 * See SetupGetFileCompressionInfoW.
1409 DWORD WINAPI
SetupGetFileCompressionInfoA( PCSTR source
, PSTR
*name
, PDWORD source_size
,
1410 PDWORD target_size
, PUINT type
)
1413 DWORD error
, required
;
1416 TRACE("%s, %p, %p, %p, %p\n", debugstr_a(source
), name
, source_size
, target_size
, type
);
1418 if (!source
|| !name
|| !source_size
|| !target_size
|| !type
)
1419 return ERROR_INVALID_PARAMETER
;
1421 ret
= SetupGetFileCompressionInfoExA( source
, NULL
, 0, &required
, NULL
, NULL
, NULL
);
1422 if (!(actual_name
= MyMalloc( required
))) return ERROR_NOT_ENOUGH_MEMORY
;
1424 ret
= SetupGetFileCompressionInfoExA( source
, actual_name
, required
, &required
,
1425 source_size
, target_size
, type
);
1428 error
= GetLastError();
1429 MyFree( actual_name
);
1432 *name
= actual_name
;
1433 return ERROR_SUCCESS
;
1436 /***********************************************************************
1437 * SetupGetFileCompressionInfoW (SETUPAPI.@)
1439 * Get compression type and compressed/uncompressed sizes of a given file.
1442 * source [I] File to examine.
1443 * name [O] Actual filename used.
1444 * source_size [O] Size of compressed file.
1445 * target_size [O] Size of uncompressed file.
1446 * type [O] Compression type.
1449 * Success: ERROR_SUCCESS
1450 * Failure: Win32 error code.
1452 DWORD WINAPI
SetupGetFileCompressionInfoW( PCWSTR source
, PWSTR
*name
, PDWORD source_size
,
1453 PDWORD target_size
, PUINT type
)
1456 DWORD error
, required
;
1459 TRACE("%s, %p, %p, %p, %p\n", debugstr_w(source
), name
, source_size
, target_size
, type
);
1461 if (!source
|| !name
|| !source_size
|| !target_size
|| !type
)
1462 return ERROR_INVALID_PARAMETER
;
1464 ret
= SetupGetFileCompressionInfoExW( source
, NULL
, 0, &required
, NULL
, NULL
, NULL
);
1465 if (!(actual_name
= MyMalloc( required
* sizeof(WCHAR
) )))
1466 return ERROR_NOT_ENOUGH_MEMORY
;
1468 ret
= SetupGetFileCompressionInfoExW( source
, actual_name
, required
, &required
,
1469 source_size
, target_size
, type
);
1472 error
= GetLastError();
1473 MyFree( actual_name
);
1476 *name
= actual_name
;
1477 return ERROR_SUCCESS
;
1480 static DWORD
decompress_file_lz( LPCWSTR source
, LPCWSTR target
)
1487 if ((src
= LZOpenFileW( (LPWSTR
)source
, &sof
, OF_READ
)) < 0)
1489 ERR("cannot open source file for reading\n");
1490 return ERROR_FILE_NOT_FOUND
;
1492 if ((dst
= LZOpenFileW( (LPWSTR
)target
, &dof
, OF_CREATE
)) < 0)
1494 ERR("cannot open target file for writing\n");
1496 return ERROR_FILE_NOT_FOUND
;
1498 if ((error
= LZCopy( src
, dst
)) >= 0) ret
= ERROR_SUCCESS
;
1501 WARN("failed to decompress file %d\n", error
);
1502 ret
= ERROR_INVALID_DATA
;
1510 struct callback_context
1516 static UINT CALLBACK
decompress_or_copy_callback( PVOID context
, UINT notification
, UINT_PTR param1
, UINT_PTR param2
)
1518 struct callback_context
*context_info
= context
;
1519 FILE_IN_CABINET_INFO_W
*info
= (FILE_IN_CABINET_INFO_W
*)param1
;
1521 switch (notification
)
1523 case SPFILENOTIFY_FILEINCABINET
:
1525 if (context_info
->has_extracted
)
1526 return FILEOP_ABORT
;
1528 TRACE("Requesting extraction of cabinet file %s\n",
1529 wine_dbgstr_w(info
->NameInCabinet
));
1530 lstrcpyW( info
->FullTargetName
, context_info
->target
);
1531 context_info
->has_extracted
= TRUE
;
1534 default: return NO_ERROR
;
1538 static DWORD
decompress_file_cab( LPCWSTR source
, LPCWSTR target
)
1540 struct callback_context context
= {0, target
};
1543 ret
= SetupIterateCabinetW( source
, 0, decompress_or_copy_callback
, &context
);
1545 if (ret
) return ERROR_SUCCESS
;
1546 else return GetLastError();
1549 /***********************************************************************
1550 * SetupDecompressOrCopyFileA (SETUPAPI.@)
1552 * See SetupDecompressOrCopyFileW.
1554 DWORD WINAPI
SetupDecompressOrCopyFileA( PCSTR source
, PCSTR target
, PUINT type
)
1557 WCHAR
*sourceW
= NULL
, *targetW
= NULL
;
1559 if (source
&& !(sourceW
= MultiByteToUnicode( source
, CP_ACP
))) return FALSE
;
1560 if (target
&& !(targetW
= MultiByteToUnicode( target
, CP_ACP
)))
1563 return ERROR_NOT_ENOUGH_MEMORY
;
1566 ret
= SetupDecompressOrCopyFileW( sourceW
, targetW
, type
);
1574 /***********************************************************************
1575 * SetupDecompressOrCopyFileW (SETUPAPI.@)
1577 * Copy a file and decompress it if needed.
1580 * source [I] File to copy.
1581 * target [I] Filename of the copy.
1582 * type [I] Compression type.
1585 * Success: ERROR_SUCCESS
1586 * Failure: Win32 error code.
1588 DWORD WINAPI
SetupDecompressOrCopyFileW( PCWSTR source
, PCWSTR target
, PUINT type
)
1591 DWORD ret
= ERROR_INVALID_PARAMETER
;
1593 TRACE("(%s, %s, %p)\n", debugstr_w(source
), debugstr_w(target
), type
);
1595 if (!source
|| !target
) return ERROR_INVALID_PARAMETER
;
1599 comp
= detect_compression_type( source
);
1600 TRACE("Detected compression type %u\n", comp
);
1605 TRACE("Using specified compression type %u\n", comp
);
1610 case FILE_COMPRESSION_NONE
:
1611 if (CopyFileW( source
, target
, FALSE
)) ret
= ERROR_SUCCESS
;
1612 else ret
= GetLastError();
1614 case FILE_COMPRESSION_WINLZA
:
1615 ret
= decompress_file_lz( source
, target
);
1617 case FILE_COMPRESSION_NTCAB
:
1618 case FILE_COMPRESSION_MSZIP
:
1619 ret
= decompress_file_cab( source
, target
);
1622 WARN("unknown compression type %d\n", comp
);
1626 TRACE("%s -> %s %d\n", debugstr_w(source
), debugstr_w(target
), comp
);
1630 static BOOL non_interactive_mode
;
1632 /***********************************************************************
1633 * SetupGetNonInteractiveMode (SETUPAPI.@)
1635 BOOL WINAPI
SetupGetNonInteractiveMode( void )
1638 return non_interactive_mode
;
1641 /***********************************************************************
1642 * SetupSetNonInteractiveMode (SETUPAPI.@)
1644 BOOL WINAPI
SetupSetNonInteractiveMode( BOOL flag
)
1646 BOOL ret
= non_interactive_mode
;
1648 FIXME("%d\n", flag
);
1650 non_interactive_mode
= flag
;
1654 /***********************************************************************
1655 * SetupCloseLog(SETUPAPI.@)
1657 void WINAPI
SetupCloseLog(void)
1659 EnterCriticalSection(&setupapi_cs
);
1661 CloseHandle(setupact
);
1662 setupact
= INVALID_HANDLE_VALUE
;
1664 CloseHandle(setuperr
);
1665 setuperr
= INVALID_HANDLE_VALUE
;
1667 LeaveCriticalSection(&setupapi_cs
);
1670 /***********************************************************************
1671 * SetupOpenLog(SETUPAPI.@)
1673 BOOL WINAPI
SetupOpenLog(BOOL reserved
)
1675 WCHAR path
[MAX_PATH
];
1677 static const WCHAR setupactlog
[] = {'\\','s','e','t','u','p','a','c','t','.','l','o','g',0};
1678 static const WCHAR setuperrlog
[] = {'\\','s','e','t','u','p','e','r','r','.','l','o','g',0};
1680 EnterCriticalSection(&setupapi_cs
);
1682 if (setupact
!= INVALID_HANDLE_VALUE
&& setuperr
!= INVALID_HANDLE_VALUE
)
1684 LeaveCriticalSection(&setupapi_cs
);
1688 GetWindowsDirectoryW(path
, MAX_PATH
);
1689 lstrcatW(path
, setupactlog
);
1691 setupact
= CreateFileW(path
, FILE_GENERIC_WRITE
, FILE_SHARE_WRITE
| FILE_SHARE_READ
,
1692 NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1693 if (setupact
== INVALID_HANDLE_VALUE
)
1695 LeaveCriticalSection(&setupapi_cs
);
1699 SetFilePointer(setupact
, 0, NULL
, FILE_END
);
1701 GetWindowsDirectoryW(path
, MAX_PATH
);
1702 lstrcatW(path
, setuperrlog
);
1704 setuperr
= CreateFileW(path
, FILE_GENERIC_WRITE
, FILE_SHARE_WRITE
| FILE_SHARE_READ
,
1705 NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1706 if (setuperr
== INVALID_HANDLE_VALUE
)
1708 CloseHandle(setupact
);
1709 setupact
= INVALID_HANDLE_VALUE
;
1710 LeaveCriticalSection(&setupapi_cs
);
1714 SetFilePointer(setuperr
, 0, NULL
, FILE_END
);
1716 LeaveCriticalSection(&setupapi_cs
);
1721 /***********************************************************************
1722 * SetupLogErrorA(SETUPAPI.@)
1724 BOOL WINAPI
SetupLogErrorA(LPCSTR message
, LogSeverity severity
)
1726 static const char null
[] = "(null)";
1731 EnterCriticalSection(&setupapi_cs
);
1733 if (setupact
== INVALID_HANDLE_VALUE
|| setuperr
== INVALID_HANDLE_VALUE
)
1735 SetLastError(ERROR_FILE_INVALID
);
1740 if (message
== NULL
)
1743 len
= lstrlenA(message
);
1745 ret
= WriteFile(setupact
, message
, len
, &written
, NULL
);
1749 if (severity
>= LogSevMaximum
)
1755 if (severity
> LogSevInformation
)
1756 ret
= WriteFile(setuperr
, message
, len
, &written
, NULL
);
1759 LeaveCriticalSection(&setupapi_cs
);
1763 /***********************************************************************
1764 * SetupLogErrorW(SETUPAPI.@)
1766 BOOL WINAPI
SetupLogErrorW(LPCWSTR message
, LogSeverity severity
)
1774 len
= WideCharToMultiByte(CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1775 msg
= HeapAlloc(GetProcessHeap(), 0, len
);
1778 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1781 WideCharToMultiByte(CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1784 /* This is the normal way to proceed. The log files are ASCII files
1785 * and W is to be converted.
1787 ret
= SetupLogErrorA(msg
, severity
);
1789 HeapFree(GetProcessHeap(), 0, msg
);
1793 /***********************************************************************
1794 * CM_Get_Version (SETUPAPI.@)
1796 WORD WINAPI
CM_Get_Version(void)