📄 advpack.c
字号:
if (res == S_OK)
{
bufferW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
res = TranslateInfStringW(filenameW.Buffer, installW.Buffer,
translateW.Buffer, keyW.Buffer, bufferW,
len, &len, NULL);
if (res == S_OK)
{
*pdwRequiredSize = WideCharToMultiByte(CP_ACP, 0, bufferW, -1,
NULL, 0, NULL, NULL);
if (dwBufferSize >= *pdwRequiredSize)
{
WideCharToMultiByte(CP_ACP, 0, bufferW, -1, pszBuffer,
dwBufferSize, NULL, NULL);
}
else
res = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
HeapFree(GetProcessHeap(), 0, bufferW);
}
RtlFreeUnicodeString(&filenameW);
RtlFreeUnicodeString(&installW);
RtlFreeUnicodeString(&translateW);
RtlFreeUnicodeString(&keyW);
return res;
}
/***********************************************************************
* TranslateInfStringW (ADVPACK.@)
*
* Translates the value of a specified key in an inf file into the
* current locale by expanding string macros.
*
* PARAMS
* pszInfFilename [I] Filename of the inf file.
* pszInstallSection [I]
* pszTranslateSection [I] Inf section where the key exists.
* pszTranslateKey [I] Key to translate.
* pszBuffer [O] Contains the translated string on exit.
* dwBufferSize [I] Size on input of pszBuffer.
* pdwRequiredSize [O] Length of the translated key.
* pvReserved [I] Reserved, must be NULL.
*
* RETURNS
* Success: S_OK.
* Failure: An hresult error code.
*/
HRESULT WINAPI TranslateInfStringW(LPCWSTR pszInfFilename, LPCWSTR pszInstallSection,
LPCWSTR pszTranslateSection, LPCWSTR pszTranslateKey, LPWSTR pszBuffer,
DWORD dwBufferSize, PDWORD pdwRequiredSize, PVOID pvReserved)
{
HINF hInf;
HRESULT hret = S_OK;
TRACE("(%s, %s, %s, %s, %p, %d, %p, %p)\n",
debugstr_w(pszInfFilename), debugstr_w(pszInstallSection),
debugstr_w(pszTranslateSection), debugstr_w(pszTranslateKey),
pszBuffer, dwBufferSize,pdwRequiredSize, pvReserved);
if (!pszInfFilename || !pszTranslateSection ||
!pszTranslateKey || !pdwRequiredSize)
return E_INVALIDARG;
hInf = SetupOpenInfFileW(pszInfFilename, NULL, INF_STYLE_WIN4, NULL);
if (hInf == INVALID_HANDLE_VALUE)
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
set_ldids(hInf, pszInstallSection, NULL);
if (!SetupGetLineTextW(NULL, hInf, pszTranslateSection, pszTranslateKey,
pszBuffer, dwBufferSize, pdwRequiredSize))
{
if (dwBufferSize < *pdwRequiredSize)
hret = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
else
hret = SPAPI_E_LINE_NOT_FOUND;
}
SetupCloseInfFile(hInf);
return hret;
}
/***********************************************************************
* TranslateInfStringExA (ADVPACK.@)
*
* See TranslateInfStringExW.
*/
HRESULT WINAPI TranslateInfStringExA(HINF hInf, LPCSTR pszInfFilename,
LPCSTR pszTranslateSection, LPCSTR pszTranslateKey,
LPSTR pszBuffer, DWORD dwBufferSize,
PDWORD pdwRequiredSize, PVOID pvReserved)
{
UNICODE_STRING filenameW, sectionW, keyW;
LPWSTR bufferW;
HRESULT res;
DWORD len = 0;
TRACE("(%p, %s, %s, %s, %s, %d, %p, %p)\n", hInf, debugstr_a(pszInfFilename),
debugstr_a(pszTranslateSection), debugstr_a(pszTranslateKey),
debugstr_a(pszBuffer), dwBufferSize, pdwRequiredSize, pvReserved);
if (!pszInfFilename || !pszTranslateSection ||
!pszTranslateKey || !pdwRequiredSize)
return E_INVALIDARG;
RtlCreateUnicodeStringFromAsciiz(&filenameW, pszInfFilename);
RtlCreateUnicodeStringFromAsciiz(§ionW, pszTranslateSection);
RtlCreateUnicodeStringFromAsciiz(&keyW, pszTranslateKey);
res = TranslateInfStringExW(hInf, filenameW.Buffer, sectionW.Buffer,
keyW.Buffer, NULL, 0, &len, NULL);
if (res == S_OK)
{
bufferW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
res = TranslateInfStringExW(hInf, filenameW.Buffer, sectionW.Buffer,
keyW.Buffer, bufferW, len, &len, NULL);
if (res == S_OK)
{
*pdwRequiredSize = WideCharToMultiByte(CP_ACP, 0, bufferW, -1,
NULL, 0, NULL, NULL);
if (dwBufferSize >= *pdwRequiredSize)
{
WideCharToMultiByte(CP_ACP, 0, bufferW, -1, pszBuffer,
dwBufferSize, NULL, NULL);
}
else
res = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
HeapFree(GetProcessHeap(), 0, bufferW);
}
RtlFreeUnicodeString(&filenameW);
RtlFreeUnicodeString(§ionW);
RtlFreeUnicodeString(&keyW);
return res;
}
/***********************************************************************
* TranslateInfStringExW (ADVPACK.@)
*
* Using a handle to an INF file opened with OpenINFEngine, translates
* the value of a specified key in an inf file into the current locale
* by expanding string macros.
*
* PARAMS
* hInf [I] Handle to the INF file.
* pszInfFilename [I] Filename of the INF file.
* pszTranslateSection [I] Inf section where the key exists.
* pszTranslateKey [I] Key to translate.
* pszBuffer [O] Contains the translated string on exit.
* dwBufferSize [I] Size on input of pszBuffer.
* pdwRequiredSize [O] Length of the translated key.
* pvReserved [I] Reserved. Must be NULL.
*
* RETURNS
* Success: S_OK.
* Failure: E_FAIL.
*
* NOTES
* To use TranslateInfStringEx to translate an INF file continuously,
* open the INF file with OpenINFEngine, call TranslateInfStringEx as
* many times as needed, then release the handle with CloseINFEngine.
* When translating more than one keys, this method is more efficient
* than calling TranslateInfString, because the INF file is only
* opened once.
*/
HRESULT WINAPI TranslateInfStringExW(HINF hInf, LPCWSTR pszInfFilename,
LPCWSTR pszTranslateSection, LPCWSTR pszTranslateKey,
LPWSTR pszBuffer, DWORD dwBufferSize,
PDWORD pdwRequiredSize, PVOID pvReserved)
{
TRACE("(%p, %s, %s, %s, %s, %d, %p, %p)\n", hInf, debugstr_w(pszInfFilename),
debugstr_w(pszTranslateSection), debugstr_w(pszTranslateKey),
debugstr_w(pszBuffer), dwBufferSize, pdwRequiredSize, pvReserved);
if (!hInf || !pszInfFilename || !pszTranslateSection || !pszTranslateKey)
return E_INVALIDARG;
if (!SetupGetLineTextW(NULL, hInf, pszTranslateSection, pszTranslateKey,
pszBuffer, dwBufferSize, pdwRequiredSize))
{
if (dwBufferSize < *pdwRequiredSize)
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
return SPAPI_E_LINE_NOT_FOUND;
}
return S_OK;
}
/***********************************************************************
* UserInstStubWrapperA (ADVPACK.@)
*
* See UserInstStubWrapperW.
*/
HRESULT WINAPI UserInstStubWrapperA(HWND hWnd, HINSTANCE hInstance,
LPSTR pszParms, INT nShow)
{
UNICODE_STRING parmsW;
HRESULT res;
TRACE("(%p, %p, %s, %i)\n", hWnd, hInstance, debugstr_a(pszParms), nShow);
if (!pszParms)
return E_INVALIDARG;
RtlCreateUnicodeStringFromAsciiz(&parmsW, pszParms);
res = UserInstStubWrapperW(hWnd, hInstance, parmsW.Buffer, nShow);
RtlFreeUnicodeString(&parmsW);
return res;
}
/***********************************************************************
* UserInstStubWrapperW (ADVPACK.@)
*
* Launches the user stub wrapper specified by the RealStubPath
* registry value under Installed Components\szParms.
*
* PARAMS
* hWnd [I] Handle to the window used for the display.
* hInstance [I] Instance of the process.
* szParms [I] The GUID of the installation.
* show [I] How the window should be shown.
*
* RETURNS
* Success: S_OK.
* Failure: E_FAIL.
*
* TODO
* If the type of the StubRealPath value is REG_EXPAND_SZ, then
* we should call ExpandEnvironmentStrings on the value and
* launch the result.
*/
HRESULT WINAPI UserInstStubWrapperW(HWND hWnd, HINSTANCE hInstance,
LPWSTR pszParms, INT nShow)
{
HKEY setup, guid;
WCHAR stub[MAX_PATH];
DWORD size = MAX_PATH;
HRESULT hr = S_OK;
BOOL res;
static const WCHAR real_stub_path[] = {
'R','e','a','l','S','t','u','b','P','a','t','h',0
};
TRACE("(%p, %p, %s, %i)\n", hWnd, hInstance, debugstr_w(pszParms), nShow);
if (!pszParms || !*pszParms)
return E_INVALIDARG;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, setup_key, 0, KEY_READ, &setup))
{
return E_FAIL;
}
if (RegOpenKeyExW(setup, pszParms, 0, KEY_READ, &guid))
{
RegCloseKey(setup);
return E_FAIL;
}
res = RegQueryValueExW(guid, real_stub_path, NULL, NULL, (LPBYTE)stub, &size);
if (res || !*stub)
goto done;
/* launch the user stub wrapper */
hr = launch_exe(stub, NULL, NULL);
done:
RegCloseKey(setup);
RegCloseKey(guid);
return hr;
}
/***********************************************************************
* UserUnInstStubWrapperA (ADVPACK.@)
*
* See UserUnInstStubWrapperW.
*/
HRESULT WINAPI UserUnInstStubWrapperA(HWND hWnd, HINSTANCE hInstance,
LPSTR pszParms, INT nShow)
{
UNICODE_STRING parmsW;
HRESULT res;
TRACE("(%p, %p, %s, %i)\n", hWnd, hInstance, debugstr_a(pszParms), nShow);
if (!pszParms)
return E_INVALIDARG;
RtlCreateUnicodeStringFromAsciiz(&parmsW, pszParms);
res = UserUnInstStubWrapperW(hWnd, hInstance, parmsW.Buffer, nShow);
RtlFreeUnicodeString(&parmsW);
return res;
}
/***********************************************************************
* UserUnInstStubWrapperW (ADVPACK.@)
*/
HRESULT WINAPI UserUnInstStubWrapperW(HWND hWnd, HINSTANCE hInstance,
LPWSTR pszParms, INT nShow)
{
FIXME("(%p, %p, %s, %i): stub\n", hWnd, hInstance, debugstr_w(pszParms), nShow);
return E_FAIL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -