4 * Copyright 2004 Huw D M Davies
5 * Copyright 2005 Sami Aario
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
22 #include "advpack_private.h"
24 typedef HRESULT (WINAPI
*DLLREGISTER
) (void);
26 #define MAX_FIELD_LENGTH 512
29 /* registry path of the Installed Components key for per-user stubs */
30 static const WCHAR setup_key
[] = {
31 'S','O','F','T','W','A','R','E','\\',
32 'M','i','c','r','o','s','o','f','t','\\',
33 'A','c','t','i','v','e',' ','S','e','t','u','p','\\',
34 'I','n','s','t','a','l','l','e','d',' ',
35 'C','o','m','p','o','n','e','n','t','s',0
38 /* Strip single quotes from a token - note size includes NULL */
39 static void strip_quotes(WCHAR
*buffer
, DWORD
*size
)
41 if (buffer
[0] == '\'' && (*size
> 1) && buffer
[*size
-2]=='\'')
45 memmove(buffer
, buffer
+ 1, *size
* sizeof(WCHAR
));
49 /* parses the destination directory parameters from pszSection
50 * the parameters are of the form: root,key,value,unknown,fallback
51 * we first read the reg value root\\key\\value and if that fails,
52 * use fallback as the destination directory
54 static void get_dest_dir(HINF hInf
, PCWSTR pszSection
, PWSTR pszBuffer
, DWORD dwSize
)
57 WCHAR key
[MAX_PATH
+ 2], value
[MAX_PATH
+ 2];
58 WCHAR prefix
[PREFIX_LEN
+ 2];
59 HKEY root
, subkey
= 0;
62 static const WCHAR hklm
[] = {'H','K','L','M',0};
63 static const WCHAR hkcu
[] = {'H','K','C','U',0};
65 /* load the destination parameters */
66 SetupFindFirstLineW(hInf
, pszSection
, NULL
, &context
);
67 SetupGetStringFieldW(&context
, 1, prefix
, PREFIX_LEN
+ 2, &size
);
68 strip_quotes(prefix
, &size
);
69 SetupGetStringFieldW(&context
, 2, key
, MAX_PATH
+ 2, &size
);
70 strip_quotes(key
, &size
);
71 SetupGetStringFieldW(&context
, 3, value
, MAX_PATH
+ 2, &size
);
72 strip_quotes(value
, &size
);
74 if (!lstrcmpW(prefix
, hklm
))
75 root
= HKEY_LOCAL_MACHINE
;
76 else if (!lstrcmpW(prefix
, hkcu
))
77 root
= HKEY_CURRENT_USER
;
81 size
= dwSize
* sizeof(WCHAR
);
83 /* fallback to the default destination dir if reg fails */
84 if (RegOpenKeyW(root
, key
, &subkey
) ||
85 RegQueryValueExW(subkey
, value
, NULL
, NULL
, (LPBYTE
)pszBuffer
, &size
))
87 SetupGetStringFieldW(&context
, 5, pszBuffer
, dwSize
, &size
);
88 strip_quotes(pszBuffer
, &size
);
91 if (subkey
) RegCloseKey(subkey
);
94 /* loads the LDIDs specified in the install section of an INF */
95 void set_ldids(HINF hInf
, LPCWSTR pszInstallSection
, LPCWSTR pszWorkingDir
)
97 WCHAR field
[MAX_FIELD_LENGTH
];
98 WCHAR line
[MAX_FIELD_LENGTH
];
104 static const WCHAR source_dir
[] = {'S','o','u','r','c','e','D','i','r',0};
106 static const WCHAR custDestW
[] = {
107 'C','u','s','t','o','m','D','e','s','t','i','n','a','t','i','o','n',0
110 if (!SetupGetLineTextW(NULL
, hInf
, pszInstallSection
, custDestW
,
111 field
, MAX_FIELD_LENGTH
, &size
))
114 if (!SetupFindFirstLineW(hInf
, field
, NULL
, &context
))
119 LPWSTR value
, ptr
, key
, key_copy
= NULL
;
122 SetupGetLineTextW(&context
, NULL
, NULL
, NULL
,
123 line
, MAX_FIELD_LENGTH
, &size
);
125 /* SetupGetLineTextW returns the value if there is only one key, but
126 * returns the whole line if there is more than one key
128 if (!(value
= strchrW(line
, '=')))
130 SetupGetStringFieldW(&context
, 0, NULL
, 0, &size
);
131 key
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
133 SetupGetStringFieldW(&context
, 0, key
, size
, &size
);
142 /* remove leading whitespace from the value */
143 while (*value
== ' ')
146 /* Extract the flags */
147 ptr
= strchrW(value
, ',');
150 flags
= atolW(ptr
+1);
153 /* set dest to pszWorkingDir if key is SourceDir */
154 if (pszWorkingDir
&& !lstrcmpiW(value
, source_dir
))
155 lstrcpynW(dest
, pszWorkingDir
, MAX_PATH
);
157 get_dest_dir(hInf
, value
, dest
, MAX_PATH
);
159 /* If prompting required, provide dialog to request path */
161 FIXME("Need to support changing paths - default will be used\n");
163 /* set all ldids to dest */
164 while ((ptr
= get_parameter(&key
, ',', FALSE
)))
167 SetupSetDirectoryIdW(hInf
, ldid
, dest
);
169 HeapFree(GetProcessHeap(), 0, key_copy
);
170 } while (SetupFindNextLine(&context
, &context
));
173 /***********************************************************************
174 * CloseINFEngine (ADVPACK.@)
176 * Closes a handle to an INF file opened with OpenINFEngine.
179 * hInf [I] Handle to the INF file to close.
185 HRESULT WINAPI
CloseINFEngine(HINF hInf
)
187 TRACE("(%p)\n", hInf
);
192 SetupCloseInfFile(hInf
);
196 /***********************************************************************
197 * DllMain (ADVPACK.@)
199 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
201 TRACE("(%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
203 if (fdwReason
== DLL_PROCESS_ATTACH
)
204 DisableThreadLibraryCalls(hinstDLL
);
209 /***********************************************************************
210 * IsNTAdmin (ADVPACK.@)
212 * Checks if the user has admin privileges.
215 * reserved [I] Reserved. Must be 0.
216 * pReserved [I] Reserved. Must be NULL.
219 * TRUE if user has admin rights, FALSE otherwise.
221 BOOL WINAPI
IsNTAdmin(DWORD reserved
, LPDWORD pReserved
)
223 SID_IDENTIFIER_AUTHORITY SidAuthority
= {SECURITY_NT_AUTHORITY
};
224 PTOKEN_GROUPS pTokenGroups
;
225 BOOL bSidFound
= FALSE
;
230 TRACE("(%d, %p)\n", reserved
, pReserved
);
232 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
235 if (!GetTokenInformation(hToken
, TokenGroups
, NULL
, 0, &dwSize
))
237 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
244 pTokenGroups
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
251 if (!GetTokenInformation(hToken
, TokenGroups
, pTokenGroups
, dwSize
, &dwSize
))
253 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
260 if (!AllocateAndInitializeSid(&SidAuthority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
261 DOMAIN_ALIAS_RID_ADMINS
, 0, 0, 0, 0, 0, 0, &pSid
))
263 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
267 for (i
= 0; i
< pTokenGroups
->GroupCount
; i
++)
269 if (EqualSid(pSid
, pTokenGroups
->Groups
[i
].Sid
))
276 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
282 /***********************************************************************
283 * NeedRebootInit (ADVPACK.@)
285 * Sets up conditions for reboot checking.
288 * Value required by NeedReboot.
290 DWORD WINAPI
NeedRebootInit(VOID
)
292 FIXME("(VOID): stub\n");
296 /***********************************************************************
297 * NeedReboot (ADVPACK.@)
299 * Determines whether a reboot is required.
302 * dwRebootCheck [I] Value from NeedRebootInit.
305 * TRUE if a reboot is needed, FALSE otherwise.
310 BOOL WINAPI
NeedReboot(DWORD dwRebootCheck
)
312 FIXME("(%d): stub\n", dwRebootCheck
);
316 /***********************************************************************
317 * OpenINFEngineA (ADVPACK.@)
319 * See OpenINFEngineW.
321 HRESULT WINAPI
OpenINFEngineA(LPCSTR pszInfFilename
, LPCSTR pszInstallSection
,
322 DWORD dwFlags
, HINF
*phInf
, PVOID pvReserved
)
324 UNICODE_STRING filenameW
, installW
;
327 TRACE("(%s, %s, %d, %p, %p)\n", debugstr_a(pszInfFilename
),
328 debugstr_a(pszInstallSection
), dwFlags
, phInf
, pvReserved
);
330 if (!pszInfFilename
|| !phInf
)
333 RtlCreateUnicodeStringFromAsciiz(&filenameW
, pszInfFilename
);
334 RtlCreateUnicodeStringFromAsciiz(&installW
, pszInstallSection
);
336 res
= OpenINFEngineW(filenameW
.Buffer
, installW
.Buffer
,
337 dwFlags
, phInf
, pvReserved
);
339 RtlFreeUnicodeString(&filenameW
);
340 RtlFreeUnicodeString(&installW
);
345 /***********************************************************************
346 * OpenINFEngineW (ADVPACK.@)
348 * Opens and returns a handle to an INF file to be used by
349 * TranslateInfStringEx to continuously translate the INF file.
352 * pszInfFilename [I] Filename of the INF to open.
353 * pszInstallSection [I] Name of the Install section in the INF.
354 * dwFlags [I] See advpub.h.
355 * phInf [O] Handle to the loaded INF file.
356 * pvReserved [I] Reserved. Must be NULL.
362 HRESULT WINAPI
OpenINFEngineW(LPCWSTR pszInfFilename
, LPCWSTR pszInstallSection
,
363 DWORD dwFlags
, HINF
*phInf
, PVOID pvReserved
)
365 TRACE("(%s, %s, %d, %p, %p)\n", debugstr_w(pszInfFilename
),
366 debugstr_w(pszInstallSection
), dwFlags
, phInf
, pvReserved
);
368 if (!pszInfFilename
|| !phInf
)
371 *phInf
= SetupOpenInfFileW(pszInfFilename
, NULL
, INF_STYLE_WIN4
, NULL
);
372 if (*phInf
== INVALID_HANDLE_VALUE
)
373 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
375 set_ldids(*phInf
, pszInstallSection
, NULL
);
380 /***********************************************************************
381 * RebootCheckOnInstallA (ADVPACK.@)
383 * See RebootCheckOnInstallW.
385 HRESULT WINAPI
RebootCheckOnInstallA(HWND hWnd
, LPCSTR pszINF
,
386 LPCSTR pszSec
, DWORD dwReserved
)
388 UNICODE_STRING infW
, secW
;
391 TRACE("(%p, %s, %s, %d)\n", hWnd
, debugstr_a(pszINF
),
392 debugstr_a(pszSec
), dwReserved
);
394 if (!pszINF
|| !pszSec
)
397 RtlCreateUnicodeStringFromAsciiz(&infW
, pszINF
);
398 RtlCreateUnicodeStringFromAsciiz(&secW
, pszSec
);
400 res
= RebootCheckOnInstallW(hWnd
, infW
.Buffer
, secW
.Buffer
, dwReserved
);
402 RtlFreeUnicodeString(&infW
);
403 RtlFreeUnicodeString(&secW
);
408 /***********************************************************************
409 * RebootCheckOnInstallW (ADVPACK.@)
411 * Checks if a reboot is required for an installed INF section.
414 * hWnd [I] Handle to the window used for messages.
415 * pszINF [I] Filename of the INF file.
416 * pszSec [I] INF section to check.
417 * dwReserved [I] Reserved. Must be 0.
420 * Success: S_OK - Reboot is needed if the INF section is installed.
421 * S_FALSE - Reboot is not needed.
422 * Failure: HRESULT of GetLastError().
425 * if pszSec is NULL, RebootCheckOnInstall checks the DefaultInstall
426 * or DefaultInstall.NT section.
431 HRESULT WINAPI
RebootCheckOnInstallW(HWND hWnd
, LPCWSTR pszINF
,
432 LPCWSTR pszSec
, DWORD dwReserved
)
434 FIXME("(%p, %s, %s, %d): stub\n", hWnd
, debugstr_w(pszINF
),
435 debugstr_w(pszSec
), dwReserved
);
440 /* registers the OCX if do_reg is TRUE, unregisters it otherwise */
441 HRESULT
do_ocx_reg(HMODULE hocx
, BOOL do_reg
, const WCHAR
*flags
, const WCHAR
*param
)
443 DLLREGISTER reg_func
;
446 reg_func
= (DLLREGISTER
)GetProcAddress(hocx
, "DllRegisterServer");
448 reg_func
= (DLLREGISTER
)GetProcAddress(hocx
, "DllUnregisterServer");
457 /***********************************************************************
458 * RegisterOCX (ADVPACK.@)
463 * hWnd [I] Handle to the window used for the display.
464 * hInst [I] Instance of the process.
465 * cmdline [I] Contains parameters in the order OCX,flags,param.
466 * show [I] How the window should be shown.
473 * OCX - Filename of the OCX to register.
474 * flags - Controls the operation of RegisterOCX.
475 * 'I' Call DllRegisterServer and DllInstall.
476 * 'N' Only call DllInstall.
477 * param - Command line passed to DllInstall.
479 HRESULT WINAPI
RegisterOCX(HWND hWnd
, HINSTANCE hInst
, LPCSTR cmdline
, INT show
)
481 LPWSTR ocx_filename
, str_flags
, param
;
482 LPWSTR cmdline_copy
, cmdline_ptr
;
483 UNICODE_STRING cmdlineW
;
488 TRACE("(%s)\n", debugstr_a(cmdline
));
490 RtlCreateUnicodeStringFromAsciiz(&cmdlineW
, cmdline
);
492 size
= (lstrlenW(cmdlineW
.Buffer
) + 1) * sizeof(WCHAR
);
493 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, size
);
494 cmdline_ptr
= cmdline_copy
;
495 lstrcpyW(cmdline_copy
, cmdlineW
.Buffer
);
497 ocx_filename
= get_parameter(&cmdline_ptr
, ',', TRUE
);
498 if (!ocx_filename
|| !*ocx_filename
)
501 str_flags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
502 param
= get_parameter(&cmdline_ptr
, ',', TRUE
);
504 hm
= LoadLibraryExW(ocx_filename
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
508 hr
= do_ocx_reg(hm
, TRUE
, str_flags
, param
);
512 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
513 RtlFreeUnicodeString(&cmdlineW
);
518 /***********************************************************************
519 * SetPerUserSecValuesA (ADVPACK.@)
521 * See SetPerUserSecValuesW.
523 HRESULT WINAPI
SetPerUserSecValuesA(PERUSERSECTIONA
* pPerUser
)
525 PERUSERSECTIONW perUserW
;
527 TRACE("(%p)\n", pPerUser
);
532 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szGUID
, -1, perUserW
.szGUID
,
533 sizeof(perUserW
.szGUID
) / sizeof(WCHAR
));
534 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szDispName
, -1, perUserW
.szDispName
,
535 sizeof(perUserW
.szDispName
) / sizeof(WCHAR
));
536 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szLocale
, -1, perUserW
.szLocale
,
537 sizeof(perUserW
.szLocale
) / sizeof(WCHAR
));
538 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szStub
, -1, perUserW
.szStub
,
539 sizeof(perUserW
.szStub
) / sizeof(WCHAR
));
540 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szVersion
, -1, perUserW
.szVersion
,
541 sizeof(perUserW
.szVersion
) / sizeof(WCHAR
));
542 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szCompID
, -1, perUserW
.szCompID
,
543 sizeof(perUserW
.szCompID
) / sizeof(WCHAR
));
544 perUserW
.dwIsInstalled
= pPerUser
->dwIsInstalled
;
545 perUserW
.bRollback
= pPerUser
->bRollback
;
547 return SetPerUserSecValuesW(&perUserW
);
550 /***********************************************************************
551 * SetPerUserSecValuesW (ADVPACK.@)
553 * Prepares the per-user stub values under IsInstalled\{GUID} that
554 * control the per-user installation.
557 * pPerUser [I] Per-user stub values.
563 HRESULT WINAPI
SetPerUserSecValuesW(PERUSERSECTIONW
* pPerUser
)
567 static const WCHAR stub_path
[] = {'S','t','u','b','P','a','t','h',0};
568 static const WCHAR version
[] = {'V','e','r','s','i','o','n',0};
569 static const WCHAR locale
[] = {'L','o','c','a','l','e',0};
570 static const WCHAR compid
[] = {'C','o','m','p','o','n','e','n','t','I','D',0};
571 static const WCHAR isinstalled
[] = {'I','s','I','n','s','t','a','l','l','e','d',0};
573 TRACE("(%p)\n", pPerUser
);
575 if (!pPerUser
|| !*pPerUser
->szGUID
)
578 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, setup_key
, 0, NULL
, 0, KEY_WRITE
,
584 if (RegCreateKeyExW(setup
, pPerUser
->szGUID
, 0, NULL
, 0, KEY_ALL_ACCESS
,
591 if (*pPerUser
->szStub
)
593 RegSetValueExW(guid
, stub_path
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szStub
,
594 (lstrlenW(pPerUser
->szStub
) + 1) * sizeof(WCHAR
));
597 if (*pPerUser
->szVersion
)
599 RegSetValueExW(guid
, version
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szVersion
,
600 (lstrlenW(pPerUser
->szVersion
) + 1) * sizeof(WCHAR
));
603 if (*pPerUser
->szLocale
)
605 RegSetValueExW(guid
, locale
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szLocale
,
606 (lstrlenW(pPerUser
->szLocale
) + 1) * sizeof(WCHAR
));
609 if (*pPerUser
->szCompID
)
611 RegSetValueExW(guid
, compid
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szCompID
,
612 (lstrlenW(pPerUser
->szCompID
) + 1) * sizeof(WCHAR
));
615 if (*pPerUser
->szDispName
)
617 RegSetValueExW(guid
, NULL
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szDispName
,
618 (lstrlenW(pPerUser
->szDispName
) + 1) * sizeof(WCHAR
));
621 RegSetValueExW(guid
, isinstalled
, 0, REG_DWORD
,
622 (LPBYTE
)&pPerUser
->dwIsInstalled
, sizeof(DWORD
));
630 /***********************************************************************
631 * TranslateInfStringA (ADVPACK.@)
633 * See TranslateInfStringW.
635 HRESULT WINAPI
TranslateInfStringA(LPCSTR pszInfFilename
, LPCSTR pszInstallSection
,
636 LPCSTR pszTranslateSection
, LPCSTR pszTranslateKey
, LPSTR pszBuffer
,
637 DWORD dwBufferSize
, PDWORD pdwRequiredSize
, PVOID pvReserved
)
639 UNICODE_STRING filenameW
, installW
;
640 UNICODE_STRING translateW
, keyW
;
645 TRACE("(%s, %s, %s, %s, %p, %d, %p, %p)\n",
646 debugstr_a(pszInfFilename
), debugstr_a(pszInstallSection
),
647 debugstr_a(pszTranslateSection
), debugstr_a(pszTranslateKey
),
648 pszBuffer
, dwBufferSize
,pdwRequiredSize
, pvReserved
);
650 if (!pszInfFilename
|| !pszTranslateSection
||
651 !pszTranslateKey
|| !pdwRequiredSize
)
654 RtlCreateUnicodeStringFromAsciiz(&filenameW
, pszInfFilename
);
655 RtlCreateUnicodeStringFromAsciiz(&installW
, pszInstallSection
);
656 RtlCreateUnicodeStringFromAsciiz(&translateW
, pszTranslateSection
);
657 RtlCreateUnicodeStringFromAsciiz(&keyW
, pszTranslateKey
);
659 res
= TranslateInfStringW(filenameW
.Buffer
, installW
.Buffer
,
660 translateW
.Buffer
, keyW
.Buffer
, NULL
,
661 dwBufferSize
, &len
, NULL
);
665 bufferW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
667 res
= TranslateInfStringW(filenameW
.Buffer
, installW
.Buffer
,
668 translateW
.Buffer
, keyW
.Buffer
, bufferW
,
672 *pdwRequiredSize
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1,
673 NULL
, 0, NULL
, NULL
);
675 if (dwBufferSize
>= *pdwRequiredSize
)
677 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, pszBuffer
,
678 dwBufferSize
, NULL
, NULL
);
681 res
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
684 HeapFree(GetProcessHeap(), 0, bufferW
);
687 RtlFreeUnicodeString(&filenameW
);
688 RtlFreeUnicodeString(&installW
);
689 RtlFreeUnicodeString(&translateW
);
690 RtlFreeUnicodeString(&keyW
);
695 /***********************************************************************
696 * TranslateInfStringW (ADVPACK.@)
698 * Translates the value of a specified key in an inf file into the
699 * current locale by expanding string macros.
702 * pszInfFilename [I] Filename of the inf file.
703 * pszInstallSection [I]
704 * pszTranslateSection [I] Inf section where the key exists.
705 * pszTranslateKey [I] Key to translate.
706 * pszBuffer [O] Contains the translated string on exit.
707 * dwBufferSize [I] Size on input of pszBuffer.
708 * pdwRequiredSize [O] Length of the translated key.
709 * pvReserved [I] Reserved, must be NULL.
713 * Failure: An hresult error code.
715 HRESULT WINAPI
TranslateInfStringW(LPCWSTR pszInfFilename
, LPCWSTR pszInstallSection
,
716 LPCWSTR pszTranslateSection
, LPCWSTR pszTranslateKey
, LPWSTR pszBuffer
,
717 DWORD dwBufferSize
, PDWORD pdwRequiredSize
, PVOID pvReserved
)
722 TRACE("(%s, %s, %s, %s, %p, %d, %p, %p)\n",
723 debugstr_w(pszInfFilename
), debugstr_w(pszInstallSection
),
724 debugstr_w(pszTranslateSection
), debugstr_w(pszTranslateKey
),
725 pszBuffer
, dwBufferSize
,pdwRequiredSize
, pvReserved
);
727 if (!pszInfFilename
|| !pszTranslateSection
||
728 !pszTranslateKey
|| !pdwRequiredSize
)
731 hInf
= SetupOpenInfFileW(pszInfFilename
, NULL
, INF_STYLE_WIN4
, NULL
);
732 if (hInf
== INVALID_HANDLE_VALUE
)
733 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
735 set_ldids(hInf
, pszInstallSection
, NULL
);
737 if (!SetupGetLineTextW(NULL
, hInf
, pszTranslateSection
, pszTranslateKey
,
738 pszBuffer
, dwBufferSize
, pdwRequiredSize
))
740 if (dwBufferSize
< *pdwRequiredSize
)
741 hret
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
743 hret
= SPAPI_E_LINE_NOT_FOUND
;
746 SetupCloseInfFile(hInf
);
750 /***********************************************************************
751 * TranslateInfStringExA (ADVPACK.@)
753 * See TranslateInfStringExW.
755 HRESULT WINAPI
TranslateInfStringExA(HINF hInf
, LPCSTR pszInfFilename
,
756 LPCSTR pszTranslateSection
, LPCSTR pszTranslateKey
,
757 LPSTR pszBuffer
, DWORD dwBufferSize
,
758 PDWORD pdwRequiredSize
, PVOID pvReserved
)
760 UNICODE_STRING filenameW
, sectionW
, keyW
;
765 TRACE("(%p, %s, %s, %s, %s, %d, %p, %p)\n", hInf
, debugstr_a(pszInfFilename
),
766 debugstr_a(pszTranslateSection
), debugstr_a(pszTranslateKey
),
767 debugstr_a(pszBuffer
), dwBufferSize
, pdwRequiredSize
, pvReserved
);
769 if (!pszInfFilename
|| !pszTranslateSection
||
770 !pszTranslateKey
|| !pdwRequiredSize
)
773 RtlCreateUnicodeStringFromAsciiz(&filenameW
, pszInfFilename
);
774 RtlCreateUnicodeStringFromAsciiz(§ionW
, pszTranslateSection
);
775 RtlCreateUnicodeStringFromAsciiz(&keyW
, pszTranslateKey
);
777 res
= TranslateInfStringExW(hInf
, filenameW
.Buffer
, sectionW
.Buffer
,
778 keyW
.Buffer
, NULL
, 0, &len
, NULL
);
782 bufferW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
784 res
= TranslateInfStringExW(hInf
, filenameW
.Buffer
, sectionW
.Buffer
,
785 keyW
.Buffer
, bufferW
, len
, &len
, NULL
);
789 *pdwRequiredSize
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1,
790 NULL
, 0, NULL
, NULL
);
792 if (dwBufferSize
>= *pdwRequiredSize
)
794 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, pszBuffer
,
795 dwBufferSize
, NULL
, NULL
);
798 res
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
801 HeapFree(GetProcessHeap(), 0, bufferW
);
804 RtlFreeUnicodeString(&filenameW
);
805 RtlFreeUnicodeString(§ionW
);
806 RtlFreeUnicodeString(&keyW
);
811 /***********************************************************************
812 * TranslateInfStringExW (ADVPACK.@)
814 * Using a handle to an INF file opened with OpenINFEngine, translates
815 * the value of a specified key in an inf file into the current locale
816 * by expanding string macros.
819 * hInf [I] Handle to the INF file.
820 * pszInfFilename [I] Filename of the INF file.
821 * pszTranslateSection [I] Inf section where the key exists.
822 * pszTranslateKey [I] Key to translate.
823 * pszBuffer [O] Contains the translated string on exit.
824 * dwBufferSize [I] Size on input of pszBuffer.
825 * pdwRequiredSize [O] Length of the translated key.
826 * pvReserved [I] Reserved. Must be NULL.
833 * To use TranslateInfStringEx to translate an INF file continuously,
834 * open the INF file with OpenINFEngine, call TranslateInfStringEx as
835 * many times as needed, then release the handle with CloseINFEngine.
836 * When translating more than one keys, this method is more efficient
837 * than calling TranslateInfString, because the INF file is only
840 HRESULT WINAPI
TranslateInfStringExW(HINF hInf
, LPCWSTR pszInfFilename
,
841 LPCWSTR pszTranslateSection
, LPCWSTR pszTranslateKey
,
842 LPWSTR pszBuffer
, DWORD dwBufferSize
,
843 PDWORD pdwRequiredSize
, PVOID pvReserved
)
845 TRACE("(%p, %s, %s, %s, %s, %d, %p, %p)\n", hInf
, debugstr_w(pszInfFilename
),
846 debugstr_w(pszTranslateSection
), debugstr_w(pszTranslateKey
),
847 debugstr_w(pszBuffer
), dwBufferSize
, pdwRequiredSize
, pvReserved
);
849 if (!hInf
|| !pszInfFilename
|| !pszTranslateSection
|| !pszTranslateKey
)
852 if (!SetupGetLineTextW(NULL
, hInf
, pszTranslateSection
, pszTranslateKey
,
853 pszBuffer
, dwBufferSize
, pdwRequiredSize
))
855 if (dwBufferSize
< *pdwRequiredSize
)
856 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
858 return SPAPI_E_LINE_NOT_FOUND
;
864 /***********************************************************************
865 * UserInstStubWrapperA (ADVPACK.@)
867 * See UserInstStubWrapperW.
869 HRESULT WINAPI
UserInstStubWrapperA(HWND hWnd
, HINSTANCE hInstance
,
870 LPSTR pszParms
, INT nShow
)
872 UNICODE_STRING parmsW
;
875 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInstance
, debugstr_a(pszParms
), nShow
);
880 RtlCreateUnicodeStringFromAsciiz(&parmsW
, pszParms
);
882 res
= UserInstStubWrapperW(hWnd
, hInstance
, parmsW
.Buffer
, nShow
);
884 RtlFreeUnicodeString(&parmsW
);
889 /***********************************************************************
890 * UserInstStubWrapperW (ADVPACK.@)
892 * Launches the user stub wrapper specified by the RealStubPath
893 * registry value under Installed Components\szParms.
896 * hWnd [I] Handle to the window used for the display.
897 * hInstance [I] Instance of the process.
898 * szParms [I] The GUID of the installation.
899 * show [I] How the window should be shown.
906 * If the type of the StubRealPath value is REG_EXPAND_SZ, then
907 * we should call ExpandEnvironmentStrings on the value and
910 HRESULT WINAPI
UserInstStubWrapperW(HWND hWnd
, HINSTANCE hInstance
,
911 LPWSTR pszParms
, INT nShow
)
914 WCHAR stub
[MAX_PATH
];
915 DWORD size
= MAX_PATH
;
919 static const WCHAR real_stub_path
[] = {
920 'R','e','a','l','S','t','u','b','P','a','t','h',0
923 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInstance
, debugstr_w(pszParms
), nShow
);
925 if (!pszParms
|| !*pszParms
)
928 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, setup_key
, 0, KEY_READ
, &setup
))
933 if (RegOpenKeyExW(setup
, pszParms
, 0, KEY_READ
, &guid
))
939 res
= RegQueryValueExW(guid
, real_stub_path
, NULL
, NULL
, (LPBYTE
)stub
, &size
);
943 /* launch the user stub wrapper */
944 hr
= launch_exe(stub
, NULL
, NULL
);
953 /***********************************************************************
954 * UserUnInstStubWrapperA (ADVPACK.@)
956 * See UserUnInstStubWrapperW.
958 HRESULT WINAPI
UserUnInstStubWrapperA(HWND hWnd
, HINSTANCE hInstance
,
959 LPSTR pszParms
, INT nShow
)
961 UNICODE_STRING parmsW
;
964 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInstance
, debugstr_a(pszParms
), nShow
);
969 RtlCreateUnicodeStringFromAsciiz(&parmsW
, pszParms
);
971 res
= UserUnInstStubWrapperW(hWnd
, hInstance
, parmsW
.Buffer
, nShow
);
973 RtlFreeUnicodeString(&parmsW
);
978 /***********************************************************************
979 * UserUnInstStubWrapperW (ADVPACK.@)
981 HRESULT WINAPI
UserUnInstStubWrapperW(HWND hWnd
, HINSTANCE hInstance
,
982 LPWSTR pszParms
, INT nShow
)
984 FIXME("(%p, %p, %s, %i): stub\n", hWnd
, hInstance
, debugstr_w(pszParms
), nShow
);