msi: Add tests for removing values from .ini files.
[wine/hacks.git] / dlls / version / info.c
blobe7f7077e72be0d84194a9a751f2c30abe1895600
1 /*
2 * Implementation of VERSION.DLL - Version Info access
4 * Copyright 1996,1997 Marcus Meissner
5 * Copyright 1997 David Cuthbert
6 * Copyright 1999 Ulrich Weigand
7 * Copyright 2005 Paul Vriens
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winver.h"
32 #include "winuser.h"
33 #include "winternl.h"
34 #include "lzexpand.h"
35 #include "wine/unicode.h"
36 #include "winerror.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ver);
41 extern DWORD find_version_resource( HFILE lzfd, DWORD *reslen, DWORD *offset );
43 /******************************************************************************
45 * This function will print via standard TRACE, debug info regarding
46 * the file info structure vffi.
47 * 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
48 * Added this function to clean up the code.
50 *****************************************************************************/
51 static void print_vffi_debug(const VS_FIXEDFILEINFO *vffi)
53 BOOL versioned_printer = FALSE;
55 if((vffi->dwFileType == VFT_DLL) || (vffi->dwFileType == VFT_DRV))
57 if(vffi->dwFileSubtype == VFT2_DRV_VERSIONED_PRINTER)
58 /* this is documented for newer w2k Drivers and up */
59 versioned_printer = TRUE;
60 else if( (vffi->dwFileSubtype == VFT2_DRV_PRINTER) &&
61 (vffi->dwFileVersionMS != vffi->dwProductVersionMS) &&
62 (vffi->dwFileVersionMS > 0) &&
63 (vffi->dwFileVersionMS <= 3) )
64 /* found this on NT 3.51, NT4.0 and old w2k Drivers */
65 versioned_printer = TRUE;
68 TRACE("structversion=%u.%u, ",
69 HIWORD(vffi->dwStrucVersion),LOWORD(vffi->dwStrucVersion));
70 if(versioned_printer)
72 WORD mode = LOWORD(vffi->dwFileVersionMS);
73 WORD ver_rev = HIWORD(vffi->dwFileVersionLS);
74 TRACE("fileversion=%u.%u.%u.%u (%s.major.minor.release), ",
75 (vffi->dwFileVersionMS),
76 HIBYTE(ver_rev), LOBYTE(ver_rev), LOWORD(vffi->dwFileVersionLS),
77 (mode == 3) ? "Usermode" : ((mode <= 2) ? "Kernelmode" : "?") );
79 else
81 TRACE("fileversion=%u.%u.%u.%u, ",
82 HIWORD(vffi->dwFileVersionMS),LOWORD(vffi->dwFileVersionMS),
83 HIWORD(vffi->dwFileVersionLS),LOWORD(vffi->dwFileVersionLS));
85 TRACE("productversion=%u.%u.%u.%u\n",
86 HIWORD(vffi->dwProductVersionMS),LOWORD(vffi->dwProductVersionMS),
87 HIWORD(vffi->dwProductVersionLS),LOWORD(vffi->dwProductVersionLS));
89 TRACE("flagmask=0x%x, flags=0x%x %s%s%s%s%s%s\n",
90 vffi->dwFileFlagsMask, vffi->dwFileFlags,
91 (vffi->dwFileFlags & VS_FF_DEBUG) ? "DEBUG," : "",
92 (vffi->dwFileFlags & VS_FF_PRERELEASE) ? "PRERELEASE," : "",
93 (vffi->dwFileFlags & VS_FF_PATCHED) ? "PATCHED," : "",
94 (vffi->dwFileFlags & VS_FF_PRIVATEBUILD) ? "PRIVATEBUILD," : "",
95 (vffi->dwFileFlags & VS_FF_INFOINFERRED) ? "INFOINFERRED," : "",
96 (vffi->dwFileFlags & VS_FF_SPECIALBUILD) ? "SPECIALBUILD," : "");
98 TRACE("(");
100 TRACE("OS=0x%x.0x%x ", HIWORD(vffi->dwFileOS), LOWORD(vffi->dwFileOS));
102 switch (vffi->dwFileOS&0xFFFF0000)
104 case VOS_DOS:TRACE("DOS,");break;
105 case VOS_OS216:TRACE("OS/2-16,");break;
106 case VOS_OS232:TRACE("OS/2-32,");break;
107 case VOS_NT:TRACE("NT,");break;
108 case VOS_UNKNOWN:
109 default:
110 TRACE("UNKNOWN(0x%x),",vffi->dwFileOS&0xFFFF0000);break;
113 switch (LOWORD(vffi->dwFileOS))
115 case VOS__BASE:TRACE("BASE");break;
116 case VOS__WINDOWS16:TRACE("WIN16");break;
117 case VOS__WINDOWS32:TRACE("WIN32");break;
118 case VOS__PM16:TRACE("PM16");break;
119 case VOS__PM32:TRACE("PM32");break;
120 default:
121 TRACE("UNKNOWN(0x%x)",LOWORD(vffi->dwFileOS));break;
124 TRACE(")\n");
126 switch (vffi->dwFileType)
128 case VFT_APP:TRACE("filetype=APP");break;
129 case VFT_DLL:
130 TRACE("filetype=DLL");
131 if(vffi->dwFileSubtype != 0)
133 if(versioned_printer) /* NT3.x/NT4.0 or old w2k Driver */
134 TRACE(",PRINTER");
135 TRACE(" (subtype=0x%x)", vffi->dwFileSubtype);
137 break;
138 case VFT_DRV:
139 TRACE("filetype=DRV,");
140 switch(vffi->dwFileSubtype)
142 case VFT2_DRV_PRINTER:TRACE("PRINTER");break;
143 case VFT2_DRV_KEYBOARD:TRACE("KEYBOARD");break;
144 case VFT2_DRV_LANGUAGE:TRACE("LANGUAGE");break;
145 case VFT2_DRV_DISPLAY:TRACE("DISPLAY");break;
146 case VFT2_DRV_MOUSE:TRACE("MOUSE");break;
147 case VFT2_DRV_NETWORK:TRACE("NETWORK");break;
148 case VFT2_DRV_SYSTEM:TRACE("SYSTEM");break;
149 case VFT2_DRV_INSTALLABLE:TRACE("INSTALLABLE");break;
150 case VFT2_DRV_SOUND:TRACE("SOUND");break;
151 case VFT2_DRV_COMM:TRACE("COMM");break;
152 case VFT2_DRV_INPUTMETHOD:TRACE("INPUTMETHOD");break;
153 case VFT2_DRV_VERSIONED_PRINTER:TRACE("VERSIONED_PRINTER");break;
154 case VFT2_UNKNOWN:
155 default:
156 TRACE("UNKNOWN(0x%x)",vffi->dwFileSubtype);break;
158 break;
159 case VFT_FONT:
160 TRACE("filetype=FONT,");
161 switch (vffi->dwFileSubtype)
163 case VFT2_FONT_RASTER:TRACE("RASTER");break;
164 case VFT2_FONT_VECTOR:TRACE("VECTOR");break;
165 case VFT2_FONT_TRUETYPE:TRACE("TRUETYPE");break;
166 default:TRACE("UNKNOWN(0x%x)",vffi->dwFileSubtype);break;
168 break;
169 case VFT_VXD:TRACE("filetype=VXD");break;
170 case VFT_STATIC_LIB:TRACE("filetype=STATIC_LIB");break;
171 case VFT_UNKNOWN:
172 default:
173 TRACE("filetype=Unknown(0x%x)",vffi->dwFileType);break;
176 TRACE("\n");
177 TRACE("filedate=0x%x.0x%x\n",vffi->dwFileDateMS,vffi->dwFileDateLS);
180 /***********************************************************************
181 * Version Info Structure
184 typedef struct
186 WORD wLength;
187 WORD wValueLength;
188 CHAR szKey[1];
189 #if 0 /* variable length structure */
190 /* DWORD aligned */
191 BYTE Value[];
192 /* DWORD aligned */
193 VS_VERSION_INFO_STRUCT16 Children[];
194 #endif
195 } VS_VERSION_INFO_STRUCT16;
197 typedef struct
199 WORD wLength;
200 WORD wValueLength;
201 WORD wType;
202 WCHAR szKey[1];
203 #if 0 /* variable length structure */
204 /* DWORD aligned */
205 BYTE Value[];
206 /* DWORD aligned */
207 VS_VERSION_INFO_STRUCT32 Children[];
208 #endif
209 } VS_VERSION_INFO_STRUCT32;
211 #define VersionInfoIs16( ver ) \
212 ( ((const VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
214 #define DWORD_ALIGN( base, ptr ) \
215 ( (LPBYTE)(base) + ((((LPBYTE)(ptr) - (LPBYTE)(base)) + 3) & ~3) )
217 #define VersionInfo16_Value( ver ) \
218 DWORD_ALIGN( (ver), (ver)->szKey + strlen((ver)->szKey) + 1 )
219 #define VersionInfo32_Value( ver ) \
220 DWORD_ALIGN( (ver), (ver)->szKey + strlenW((ver)->szKey) + 1 )
222 #define VersionInfo16_Children( ver ) \
223 (const VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
224 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
225 #define VersionInfo32_Children( ver ) \
226 (const VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
227 ( ( (ver)->wValueLength * \
228 ((ver)->wType? 2 : 1) + 3 ) & ~3 ) )
230 #define VersionInfo16_Next( ver ) \
231 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
232 #define VersionInfo32_Next( ver ) \
233 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
236 /***********************************************************************
237 * GetFileVersionInfoSizeW [VERSION.@]
239 DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle )
241 DWORD len, offset, magic = 1;
242 HFILE lzfd;
243 HMODULE hModule;
244 OFSTRUCT ofs;
246 TRACE("(%s,%p)\n", debugstr_w(filename), handle );
248 if (handle) *handle = 0;
250 if (!filename)
252 SetLastError(ERROR_INVALID_PARAMETER);
253 return 0;
255 if (!*filename)
257 SetLastError(ERROR_BAD_PATHNAME);
258 return 0;
261 if ((lzfd = LZOpenFileW( (LPWSTR)filename, &ofs, OF_READ )) != HFILE_ERROR)
263 magic = find_version_resource( lzfd, &len, &offset );
264 LZClose( lzfd );
267 if ((magic == 1) && (hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE )))
269 HRSRC hRsrc = FindResourceW( hModule, MAKEINTRESOURCEW(VS_VERSION_INFO),
270 MAKEINTRESOURCEW(VS_FILE_INFO) );
271 if (hRsrc)
273 magic = IMAGE_NT_SIGNATURE;
274 len = SizeofResource( hModule, hRsrc );
276 FreeLibrary( hModule );
279 switch (magic)
281 case IMAGE_OS2_SIGNATURE:
282 /* We have a 16bit resource.
284 * XP/W2K/W2K3 uses a buffer which is more than the actual needed space:
286 * (info->wLength - sizeof(VS_FIXEDFILEINFO)) * 4
288 * This extra buffer is used for ANSI to Unicode conversions in W-Calls.
289 * info->wLength should be the same as len. Currently it isn't but that
290 * doesn't seem to be a problem (len is bigger than info->wLength).
292 SetLastError(0);
293 return (len - sizeof(VS_FIXEDFILEINFO)) * 4;
295 case IMAGE_NT_SIGNATURE:
296 /* We have a 32bit resource.
298 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
299 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
301 SetLastError(0);
302 return (len * 2) + 4;
304 default:
305 SetLastError( lzfd == HFILE_ERROR ? ofs.nErrCode : ERROR_RESOURCE_DATA_NOT_FOUND );
306 return 0;
310 /***********************************************************************
311 * GetFileVersionInfoSizeA [VERSION.@]
313 DWORD WINAPI GetFileVersionInfoSizeA( LPCSTR filename, LPDWORD handle )
315 UNICODE_STRING filenameW;
316 DWORD retval;
318 TRACE("(%s,%p)\n", debugstr_a(filename), handle );
320 if(filename)
321 RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
322 else
323 filenameW.Buffer = NULL;
325 retval = GetFileVersionInfoSizeW(filenameW.Buffer, handle);
327 RtlFreeUnicodeString(&filenameW);
329 return retval;
332 /***********************************************************************
333 * GetFileVersionInfoW [VERSION.@]
335 BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle,
336 DWORD datasize, LPVOID data )
338 static const char signature[4] = "FE2X";
339 DWORD len, offset, magic = 1;
340 HFILE lzfd;
341 OFSTRUCT ofs;
342 HMODULE hModule;
343 VS_VERSION_INFO_STRUCT32* vvis = data;
345 TRACE("(%s,%d,size=%d,data=%p)\n",
346 debugstr_w(filename), handle, datasize, data );
348 if (!data)
350 SetLastError(ERROR_INVALID_DATA);
351 return FALSE;
354 if ((lzfd = LZOpenFileW( (LPWSTR)filename, &ofs, OF_READ )) != HFILE_ERROR)
356 if ((magic = find_version_resource( lzfd, &len, &offset )) > 1)
358 LZSeek( lzfd, offset, 0 /* SEEK_SET */ );
359 len = LZRead( lzfd, data, min( len, datasize ) );
361 LZClose( lzfd );
364 if ((magic == 1) && (hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE )))
366 HRSRC hRsrc = FindResourceW( hModule, MAKEINTRESOURCEW(VS_VERSION_INFO),
367 MAKEINTRESOURCEW(VS_FILE_INFO) );
368 if (hRsrc)
370 HGLOBAL hMem = LoadResource( hModule, hRsrc );
371 magic = IMAGE_NT_SIGNATURE;
372 len = min( SizeofResource(hModule, hRsrc), datasize );
373 memcpy( data, LockResource( hMem ), len );
374 FreeResource( hMem );
376 FreeLibrary( hModule );
379 switch (magic)
381 case IMAGE_OS2_SIGNATURE:
382 /* We have a 16bit resource. */
383 if (TRACE_ON(ver))
384 print_vffi_debug( (VS_FIXEDFILEINFO *)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16 *)data ));
385 SetLastError(0);
386 return TRUE;
388 case IMAGE_NT_SIGNATURE:
389 /* We have a 32bit resource.
391 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
392 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
394 len = vvis->wLength + sizeof(signature);
395 if (datasize >= len) memcpy( (char*)data + vvis->wLength, signature, sizeof(signature) );
396 if (TRACE_ON(ver))
397 print_vffi_debug( (VS_FIXEDFILEINFO *)VersionInfo32_Value( vvis ));
398 SetLastError(0);
399 return TRUE;
401 default:
402 SetLastError( lzfd == HFILE_ERROR ? ofs.nErrCode : ERROR_RESOURCE_DATA_NOT_FOUND );
403 return FALSE;
407 /***********************************************************************
408 * GetFileVersionInfoA [VERSION.@]
410 BOOL WINAPI GetFileVersionInfoA( LPCSTR filename, DWORD handle,
411 DWORD datasize, LPVOID data )
413 UNICODE_STRING filenameW;
414 BOOL retval;
416 TRACE("(%s,%d,size=%d,data=%p)\n",
417 debugstr_a(filename), handle, datasize, data );
419 if(filename)
420 RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
421 else
422 filenameW.Buffer = NULL;
424 retval = GetFileVersionInfoW(filenameW.Buffer, handle, datasize, data);
426 RtlFreeUnicodeString(&filenameW);
428 return retval;
431 /***********************************************************************
432 * VersionInfo16_FindChild [internal]
434 static const VS_VERSION_INFO_STRUCT16 *VersionInfo16_FindChild( const VS_VERSION_INFO_STRUCT16 *info,
435 LPCSTR szKey, UINT cbKey )
437 const VS_VERSION_INFO_STRUCT16 *child = VersionInfo16_Children( info );
439 while ((char *)child < (char *)info + info->wLength )
441 if (!strncasecmp( child->szKey, szKey, cbKey ) && !child->szKey[cbKey])
442 return child;
444 if (!(child->wLength)) return NULL;
445 child = VersionInfo16_Next( child );
448 return NULL;
451 /***********************************************************************
452 * VersionInfo32_FindChild [internal]
454 static const VS_VERSION_INFO_STRUCT32 *VersionInfo32_FindChild( const VS_VERSION_INFO_STRUCT32 *info,
455 LPCWSTR szKey, UINT cbKey )
457 const VS_VERSION_INFO_STRUCT32 *child = VersionInfo32_Children( info );
459 while ((char *)child < (char *)info + info->wLength )
461 if (!strncmpiW( child->szKey, szKey, cbKey ) && !child->szKey[cbKey])
462 return child;
464 if (!(child->wLength)) return NULL;
465 child = VersionInfo32_Next( child );
468 return NULL;
471 /***********************************************************************
472 * VersionInfo16_QueryValue [internal]
474 * Gets a value from a 16-bit NE resource
476 static BOOL VersionInfo16_QueryValue( const VS_VERSION_INFO_STRUCT16 *info, LPCSTR lpSubBlock,
477 LPVOID *lplpBuffer, UINT *puLen )
479 while ( *lpSubBlock )
481 /* Find next path component */
482 LPCSTR lpNextSlash;
483 for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
484 if ( *lpNextSlash == '\\' )
485 break;
487 /* Skip empty components */
488 if ( lpNextSlash == lpSubBlock )
490 lpSubBlock++;
491 continue;
494 /* We have a non-empty component: search info for key */
495 info = VersionInfo16_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
496 if ( !info )
498 if (puLen) *puLen = 0 ;
499 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND );
500 return FALSE;
503 /* Skip path component */
504 lpSubBlock = lpNextSlash;
507 /* Return value */
508 *lplpBuffer = VersionInfo16_Value( info );
509 if (puLen)
510 *puLen = info->wValueLength;
512 return TRUE;
515 /***********************************************************************
516 * VersionInfo32_QueryValue [internal]
518 * Gets a value from a 32-bit PE resource
520 static BOOL VersionInfo32_QueryValue( const VS_VERSION_INFO_STRUCT32 *info, LPCWSTR lpSubBlock,
521 LPVOID *lplpBuffer, UINT *puLen )
523 TRACE("lpSubBlock : (%s)\n", debugstr_w(lpSubBlock));
525 while ( *lpSubBlock )
527 /* Find next path component */
528 LPCWSTR lpNextSlash;
529 for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
530 if ( *lpNextSlash == '\\' )
531 break;
533 /* Skip empty components */
534 if ( lpNextSlash == lpSubBlock )
536 lpSubBlock++;
537 continue;
540 /* We have a non-empty component: search info for key */
541 info = VersionInfo32_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
542 if ( !info )
544 if (puLen) *puLen = 0 ;
545 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND );
546 return FALSE;
549 /* Skip path component */
550 lpSubBlock = lpNextSlash;
553 /* Return value */
554 *lplpBuffer = VersionInfo32_Value( info );
555 if (puLen)
556 *puLen = info->wValueLength;
558 return TRUE;
561 /***********************************************************************
562 * VerQueryValueA [VERSION.@]
564 BOOL WINAPI VerQueryValueA( LPCVOID pBlock, LPCSTR lpSubBlock,
565 LPVOID *lplpBuffer, PUINT puLen )
567 static const char rootA[] = "\\";
568 static const char varfileinfoA[] = "\\VarFileInfo\\Translation";
569 const VS_VERSION_INFO_STRUCT16 *info = pBlock;
571 TRACE("(%p,%s,%p,%p)\n",
572 pBlock, debugstr_a(lpSubBlock), lplpBuffer, puLen );
574 if (!pBlock)
575 return FALSE;
577 if (lpSubBlock == NULL || lpSubBlock[0] == '\0')
578 lpSubBlock = rootA;
580 if ( !VersionInfoIs16( info ) )
582 BOOL ret;
583 INT len;
584 LPWSTR lpSubBlockW;
586 len = MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, NULL, 0);
587 lpSubBlockW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
589 if (!lpSubBlockW)
590 return FALSE;
592 MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, lpSubBlockW, len);
594 ret = VersionInfo32_QueryValue(pBlock, lpSubBlockW, lplpBuffer, puLen);
596 HeapFree(GetProcessHeap(), 0, lpSubBlockW);
598 if (ret && strcasecmp( lpSubBlock, rootA ) && strcasecmp( lpSubBlock, varfileinfoA ))
600 /* Set lpBuffer so it points to the 'empty' area where we store
601 * the converted strings
603 LPSTR lpBufferA = (LPSTR)pBlock + info->wLength + 4;
604 DWORD pos = (LPCSTR)*lplpBuffer - (LPCSTR)pBlock;
606 len = WideCharToMultiByte(CP_ACP, 0, *lplpBuffer, -1,
607 lpBufferA + pos, info->wLength - pos, NULL, NULL);
608 *lplpBuffer = lpBufferA + pos;
609 *puLen = len;
611 return ret;
614 return VersionInfo16_QueryValue(info, lpSubBlock, lplpBuffer, puLen);
617 /***********************************************************************
618 * VerQueryValueW [VERSION.@]
620 BOOL WINAPI VerQueryValueW( LPCVOID pBlock, LPCWSTR lpSubBlock,
621 LPVOID *lplpBuffer, PUINT puLen )
623 static const WCHAR nullW[] = { 0 };
624 static const WCHAR rootW[] = { '\\', 0 };
625 static const WCHAR varfileinfoW[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
626 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
628 const VS_VERSION_INFO_STRUCT32 *info = pBlock;
630 TRACE("(%p,%s,%p,%p)\n",
631 pBlock, debugstr_w(lpSubBlock), lplpBuffer, puLen );
633 if (!pBlock)
634 return FALSE;
636 if (lpSubBlock == NULL || lpSubBlock[0] == nullW[0])
637 lpSubBlock = rootW;
639 if ( VersionInfoIs16( info ) )
641 BOOL ret;
642 int len;
643 LPSTR lpSubBlockA;
645 len = WideCharToMultiByte(CP_ACP, 0, lpSubBlock, -1, NULL, 0, NULL, NULL);
646 lpSubBlockA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
648 if (!lpSubBlockA)
649 return FALSE;
651 WideCharToMultiByte(CP_ACP, 0, lpSubBlock, -1, lpSubBlockA, len, NULL, NULL);
653 ret = VersionInfo16_QueryValue(pBlock, lpSubBlockA, lplpBuffer, puLen);
655 HeapFree(GetProcessHeap(), 0, lpSubBlockA);
657 if (ret && strcmpiW( lpSubBlock, rootW ) && strcmpiW( lpSubBlock, varfileinfoW ))
659 /* Set lpBuffer so it points to the 'empty' area where we store
660 * the converted strings
662 LPWSTR lpBufferW = (LPWSTR)((LPSTR)pBlock + info->wLength);
663 DWORD pos = (LPCSTR)*lplpBuffer - (LPCSTR)pBlock;
664 DWORD max = (info->wLength - sizeof(VS_FIXEDFILEINFO)) * 4 - info->wLength;
666 len = MultiByteToWideChar(CP_ACP, 0, *lplpBuffer, -1,
667 lpBufferW + pos, max/sizeof(WCHAR) - pos );
668 *lplpBuffer = lpBufferW + pos;
669 *puLen = len;
671 return ret;
674 return VersionInfo32_QueryValue(info, lpSubBlock, lplpBuffer, puLen);