Added check for unhide option.
[wine.git] / dlls / version / info.c
blob29030ddec7e053eba55b06b6ea01627fc668bd85
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
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * TODO
23 * o Verify VerQueryValue()
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "winver.h"
34 #include "wine/winuser16.h"
35 #include "wine/unicode.h"
36 #include "winerror.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ver);
42 /******************************************************************************
44 * This function will print via dprintf[_]ver to stddeb debug info regarding
45 * the file info structure vffi.
46 * 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
47 * Added this function to clean up the code.
49 *****************************************************************************/
50 static void print_vffi_debug(VS_FIXEDFILEINFO *vffi)
52 TRACE(" structversion=%u.%u, fileversion=%u.%u.%u.%u, productversion=%u.%u.%u.%u, flagmask=0x%lx, flags=%s%s%s%s%s%s\n",
53 HIWORD(vffi->dwStrucVersion),LOWORD(vffi->dwStrucVersion),
54 HIWORD(vffi->dwFileVersionMS),LOWORD(vffi->dwFileVersionMS),
55 HIWORD(vffi->dwFileVersionLS),LOWORD(vffi->dwFileVersionLS),
56 HIWORD(vffi->dwProductVersionMS),LOWORD(vffi->dwProductVersionMS),
57 HIWORD(vffi->dwProductVersionLS),LOWORD(vffi->dwProductVersionLS),
58 vffi->dwFileFlagsMask,
59 (vffi->dwFileFlags & VS_FF_DEBUG) ? "DEBUG," : "",
60 (vffi->dwFileFlags & VS_FF_PRERELEASE) ? "PRERELEASE," : "",
61 (vffi->dwFileFlags & VS_FF_PATCHED) ? "PATCHED," : "",
62 (vffi->dwFileFlags & VS_FF_PRIVATEBUILD) ? "PRIVATEBUILD," : "",
63 (vffi->dwFileFlags & VS_FF_INFOINFERRED) ? "INFOINFERRED," : "",
64 (vffi->dwFileFlags & VS_FF_SPECIALBUILD) ? "SPECIALBUILD," : ""
67 TRACE("(");
68 TRACE(" OS=0x%x.0x%x ",
69 HIWORD(vffi->dwFileOS),
70 LOWORD(vffi->dwFileOS)
72 switch (vffi->dwFileOS&0xFFFF0000) {
73 case VOS_DOS:TRACE("DOS,");break;
74 case VOS_OS216:TRACE("OS/2-16,");break;
75 case VOS_OS232:TRACE("OS/2-32,");break;
76 case VOS_NT:TRACE("NT,");break;
77 case VOS_UNKNOWN:
78 default:
79 TRACE("UNKNOWN(0x%lx),",vffi->dwFileOS&0xFFFF0000);break;
81 switch (LOWORD(vffi->dwFileOS)) {
82 case VOS__BASE:TRACE("BASE");break;
83 case VOS__WINDOWS16:TRACE("WIN16");break;
84 case VOS__WINDOWS32:TRACE("WIN32");break;
85 case VOS__PM16:TRACE("PM16");break;
86 case VOS__PM32:TRACE("PM32");break;
87 default:TRACE("UNKNOWN(0x%x)",LOWORD(vffi->dwFileOS));break;
89 TRACE(")\n");
91 switch (vffi->dwFileType) {
92 default:
93 case VFT_UNKNOWN:
94 TRACE("filetype=Unknown(0x%lx)",vffi->dwFileType);
95 break;
96 case VFT_APP:TRACE("filetype=APP,");break;
97 case VFT_DLL:TRACE("filetype=DLL,");break;
98 case VFT_DRV:
99 TRACE("filetype=DRV,");
100 switch(vffi->dwFileSubtype) {
101 default:
102 case VFT2_UNKNOWN:
103 TRACE("UNKNOWN(0x%lx)",vffi->dwFileSubtype);
104 break;
105 case VFT2_DRV_PRINTER:
106 TRACE("PRINTER");
107 break;
108 case VFT2_DRV_KEYBOARD:
109 TRACE("KEYBOARD");
110 break;
111 case VFT2_DRV_LANGUAGE:
112 TRACE("LANGUAGE");
113 break;
114 case VFT2_DRV_DISPLAY:
115 TRACE("DISPLAY");
116 break;
117 case VFT2_DRV_MOUSE:
118 TRACE("MOUSE");
119 break;
120 case VFT2_DRV_NETWORK:
121 TRACE("NETWORK");
122 break;
123 case VFT2_DRV_SYSTEM:
124 TRACE("SYSTEM");
125 break;
126 case VFT2_DRV_INSTALLABLE:
127 TRACE("INSTALLABLE");
128 break;
129 case VFT2_DRV_SOUND:
130 TRACE("SOUND");
131 break;
132 case VFT2_DRV_COMM:
133 TRACE("COMM");
134 break;
135 case VFT2_DRV_INPUTMETHOD:
136 TRACE("INPUTMETHOD");
137 break;
139 break;
140 case VFT_FONT:
141 TRACE("filetype=FONT.");
142 switch (vffi->dwFileSubtype) {
143 default:
144 TRACE("UNKNOWN(0x%lx)",vffi->dwFileSubtype);
145 break;
146 case VFT2_FONT_RASTER:TRACE("RASTER");break;
147 case VFT2_FONT_VECTOR:TRACE("VECTOR");break;
148 case VFT2_FONT_TRUETYPE:TRACE("TRUETYPE");break;
150 break;
151 case VFT_VXD:TRACE("filetype=VXD");break;
152 case VFT_STATIC_LIB:TRACE("filetype=STATIC_LIB");break;
154 TRACE("\n");
155 TRACE(" filedata=0x%lx.0x%lx\n",
156 vffi->dwFileDateMS,vffi->dwFileDateLS);
160 /***********************************************************************
161 * Version Info Structure
164 typedef struct
166 WORD wLength;
167 WORD wValueLength;
168 CHAR szKey[1];
169 #if 0 /* variable length structure */
170 /* DWORD aligned */
171 BYTE Value[];
172 /* DWORD aligned */
173 VS_VERSION_INFO_STRUCT16 Children[];
174 #endif
175 } VS_VERSION_INFO_STRUCT16;
177 typedef struct
179 WORD wLength;
180 WORD wValueLength;
181 WORD bText;
182 WCHAR szKey[1];
183 #if 0 /* variable length structure */
184 /* DWORD aligned */
185 BYTE Value[];
186 /* DWORD aligned */
187 VS_VERSION_INFO_STRUCT32 Children[];
188 #endif
189 } VS_VERSION_INFO_STRUCT32;
191 #define VersionInfoIs16( ver ) \
192 ( ((VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
194 #define DWORD_ALIGN( base, ptr ) \
195 ( (LPBYTE)(base) + ((((LPBYTE)(ptr) - (LPBYTE)(base)) + 3) & ~3) )
197 #define VersionInfo16_Value( ver ) \
198 DWORD_ALIGN( (ver), (ver)->szKey + strlen((ver)->szKey) + 1 )
199 #define VersionInfo32_Value( ver ) \
200 DWORD_ALIGN( (ver), (ver)->szKey + strlenW((ver)->szKey) + 1 )
202 #define VersionInfo16_Children( ver ) \
203 (VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
204 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
205 #define VersionInfo32_Children( ver ) \
206 (VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
207 ( ( (ver)->wValueLength * \
208 ((ver)->bText? 2 : 1) + 3 ) & ~3 ) )
210 #define VersionInfo16_Next( ver ) \
211 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
212 #define VersionInfo32_Next( ver ) \
213 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
215 /***********************************************************************
216 * ConvertVersionInfo32To16 [internal]
218 void ConvertVersionInfo32To16( VS_VERSION_INFO_STRUCT32 *info32,
219 VS_VERSION_INFO_STRUCT16 *info16 )
221 /* Copy data onto local stack to prevent overwrites */
222 WORD wLength = info32->wLength;
223 WORD wValueLength = info32->wValueLength;
224 WORD bText = info32->bText;
225 LPBYTE lpValue = VersionInfo32_Value( info32 );
226 VS_VERSION_INFO_STRUCT32 *child32 = VersionInfo32_Children( info32 );
227 VS_VERSION_INFO_STRUCT16 *child16;
229 TRACE("Converting %p to %p\n", info32, info16 );
230 TRACE("wLength %d, wValueLength %d, bText %d, value %p, child %p\n",
231 wLength, wValueLength, bText, lpValue, child32 );
233 /* Convert key */
234 WideCharToMultiByte( CP_ACP, 0, info32->szKey, -1, info16->szKey, 0x7fffffff, NULL, NULL );
236 TRACE("Copied key from %p to %p: %s\n", info32->szKey, info16->szKey,
237 debugstr_a(info16->szKey) );
239 /* Convert value */
240 if ( wValueLength == 0 )
242 info16->wValueLength = 0;
243 TRACE("No value present\n" );
245 else if ( bText )
247 info16->wValueLength = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lpValue, -1, NULL, 0, NULL, NULL );
248 WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lpValue, -1,
249 VersionInfo16_Value( info16 ), info16->wValueLength, NULL, NULL );
251 TRACE("Copied value from %p to %p: %s\n", lpValue,
252 VersionInfo16_Value( info16 ),
253 debugstr_a(VersionInfo16_Value( info16 )) );
255 else
257 info16->wValueLength = wValueLength;
258 memmove( VersionInfo16_Value( info16 ), lpValue, wValueLength );
260 TRACE("Copied value from %p to %p: %d bytes\n", lpValue,
261 VersionInfo16_Value( info16 ), wValueLength );
264 /* Convert children */
265 child16 = VersionInfo16_Children( info16 );
266 while ( (DWORD)child32 < (DWORD)info32 + wLength && child32->wLength != 0 )
268 VS_VERSION_INFO_STRUCT32 *nextChild = VersionInfo32_Next( child32 );
270 ConvertVersionInfo32To16( child32, child16 );
272 child16 = VersionInfo16_Next( child16 );
273 child32 = nextChild;
276 /* Fixup length */
277 info16->wLength = (DWORD)child16 - (DWORD)info16;
279 TRACE("Finished, length is %d (%p - %p)\n",
280 info16->wLength, info16, child16 );
283 /***********************************************************************
284 * VERSION_GetFileVersionInfo_PE [internal]
286 * NOTE: returns size of the PE VERSION resource or 0xFFFFFFFF
287 * in the case if file exists, but VERSION_INFO not found.
288 * FIXME: handle is not used.
290 static DWORD VERSION_GetFileVersionInfo_PE( LPCSTR filename, LPDWORD handle,
291 DWORD datasize, LPVOID data )
293 VS_FIXEDFILEINFO *vffi;
294 DWORD len;
295 BYTE *buf;
296 HMODULE hModule;
297 HRSRC hRsrc;
298 HGLOBAL hMem;
300 TRACE("(%s,%p)\n", debugstr_a(filename), handle );
302 hModule = GetModuleHandleA(filename);
303 if(!hModule)
304 hModule = LoadLibraryExA(filename, 0, LOAD_LIBRARY_AS_DATAFILE);
305 else
306 hModule = LoadLibraryExA(filename, 0, 0);
307 if(!hModule)
309 WARN("Could not load %s\n", debugstr_a(filename));
310 return 0;
312 hRsrc = FindResourceW(hModule,
313 MAKEINTRESOURCEW(VS_VERSION_INFO),
314 MAKEINTRESOURCEW(VS_FILE_INFO));
315 if(!hRsrc)
317 WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_a(filename));
318 FreeLibrary(hModule);
319 return 0xFFFFFFFF;
321 len = SizeofResource(hModule, hRsrc);
322 hMem = LoadResource(hModule, hRsrc);
323 if(!hMem)
325 WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_a(filename));
326 FreeLibrary(hModule);
327 return 0xFFFFFFFF;
329 buf = LockResource(hMem);
331 vffi = (VS_FIXEDFILEINFO *)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32 *)buf );
333 if ( vffi->dwSignature != VS_FFI_SIGNATURE )
335 WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
336 vffi->dwSignature, VS_FFI_SIGNATURE );
337 len = 0xFFFFFFFF;
338 goto END;
341 if ( TRACE_ON(ver) )
342 print_vffi_debug( vffi );
344 if(data)
346 if(datasize < len)
347 len = datasize; /* truncate data */
348 if(len)
349 memcpy(data, buf, len);
350 else
351 len = 0xFFFFFFFF;
353 END:
354 FreeResource(hMem);
355 FreeLibrary(hModule);
357 return len;
360 /***********************************************************************
361 * VERSION_GetFileVersionInfo_16 [internal]
363 * NOTE: returns size of the 16-bit VERSION resource or 0xFFFFFFFF
364 * in the case if file exists, but VERSION_INFO not found.
365 * FIXME: handle is not used.
367 static DWORD VERSION_GetFileVersionInfo_16( LPCSTR filename, LPDWORD handle,
368 DWORD datasize, LPVOID data )
370 VS_FIXEDFILEINFO *vffi;
371 DWORD len;
372 BYTE *buf;
373 HMODULE16 hModule;
374 HRSRC16 hRsrc;
375 HGLOBAL16 hMem;
377 TRACE("(%s,%p)\n", debugstr_a(filename), handle );
379 hModule = LoadLibrary16(filename);
380 if(hModule < 32)
382 WARN("Could not load %s\n", debugstr_a(filename));
383 return 0;
385 hRsrc = FindResource16(hModule,
386 MAKEINTRESOURCEA(VS_VERSION_INFO),
387 MAKEINTRESOURCEA(VS_FILE_INFO));
388 if(!hRsrc)
390 WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_a(filename));
391 FreeLibrary16(hModule);
392 return 0xFFFFFFFF;
394 len = SizeofResource16(hModule, hRsrc);
395 hMem = LoadResource16(hModule, hRsrc);
396 if(!hMem)
398 WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_a(filename));
399 FreeLibrary16(hModule);
400 return 0xFFFFFFFF;
402 buf = LockResource16(hMem);
404 if(!VersionInfoIs16(buf))
405 goto END;
407 vffi = (VS_FIXEDFILEINFO *)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16 *)buf );
409 if ( vffi->dwSignature != VS_FFI_SIGNATURE )
411 WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
412 vffi->dwSignature, VS_FFI_SIGNATURE );
413 len = 0xFFFFFFFF;
414 goto END;
417 if ( TRACE_ON(ver) )
418 print_vffi_debug( vffi );
420 if(data)
422 if(datasize < len)
423 len = datasize; /* truncate data */
424 if(len)
425 memcpy(data, buf, len);
426 else
427 len = 0xFFFFFFFF;
429 END:
430 FreeResource16(hMem);
431 FreeLibrary16(hModule);
433 return len;
436 /***********************************************************************
437 * GetFileVersionInfoSizeA [VERSION.@]
439 DWORD WINAPI GetFileVersionInfoSizeA( LPCSTR filename, LPDWORD handle )
441 VS_FIXEDFILEINFO *vffi;
442 DWORD len, ret, offset;
443 BYTE buf[144];
445 TRACE("(%s,%p)\n", debugstr_a(filename), handle );
447 len = VERSION_GetFileVersionInfo_PE(filename, handle, 0, NULL);
448 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
449 if(len == 0xFFFFFFFF)
451 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
452 return 0;
454 if(len) return len;
455 len = VERSION_GetFileVersionInfo_16(filename, handle, 0, NULL);
456 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
457 if(len == 0xFFFFFFFF)
459 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
460 return 0;
462 if(len) return len;
464 len = GetFileResourceSize16( filename,
465 MAKEINTRESOURCEA(VS_FILE_INFO),
466 MAKEINTRESOURCEA(VS_VERSION_INFO),
467 &offset );
468 if (!len) return 0;
470 ret = GetFileResource16( filename,
471 MAKEINTRESOURCEA(VS_FILE_INFO),
472 MAKEINTRESOURCEA(VS_VERSION_INFO),
473 offset, sizeof( buf ), buf );
474 if (!ret) return 0;
476 if ( handle ) *handle = offset;
478 if ( VersionInfoIs16( buf ) )
479 vffi = (VS_FIXEDFILEINFO *)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16 *)buf );
480 else
481 vffi = (VS_FIXEDFILEINFO *)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32 *)buf );
483 if ( vffi->dwSignature != VS_FFI_SIGNATURE )
485 WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
486 vffi->dwSignature, VS_FFI_SIGNATURE );
487 return 0;
490 if ( ((VS_VERSION_INFO_STRUCT16 *)buf)->wLength < len )
491 len = ((VS_VERSION_INFO_STRUCT16 *)buf)->wLength;
493 if ( TRACE_ON(ver) )
494 print_vffi_debug( vffi );
496 return len;
499 /***********************************************************************
500 * GetFileVersionInfoSizeW [VERSION.@]
502 DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle )
504 DWORD ret, len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL );
505 LPSTR fn = HeapAlloc( GetProcessHeap(), 0, len );
506 WideCharToMultiByte( CP_ACP, 0, filename, -1, fn, len, NULL, NULL );
507 ret = GetFileVersionInfoSizeA( fn, handle );
508 HeapFree( GetProcessHeap(), 0, fn );
509 return ret;
512 /***********************************************************************
513 * GetFileVersionInfoA [VERSION.@]
515 BOOL WINAPI GetFileVersionInfoA( LPCSTR filename, DWORD handle,
516 DWORD datasize, LPVOID data )
518 DWORD len;
520 TRACE("(%s,%ld,size=%ld,data=%p)\n",
521 debugstr_a(filename), handle, datasize, data );
523 len = VERSION_GetFileVersionInfo_PE(filename, &handle, datasize, data);
524 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
525 if(len == 0xFFFFFFFF) return FALSE;
526 if(len)
527 goto DO_CONVERT;
528 len = VERSION_GetFileVersionInfo_16(filename, &handle, datasize, data);
529 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
530 if(len == 0xFFFFFFFF) return FALSE;
531 if(len)
532 goto DO_CONVERT;
534 if ( !GetFileResource16( filename, MAKEINTRESOURCEA(VS_FILE_INFO),
535 MAKEINTRESOURCEA(VS_VERSION_INFO),
536 handle, datasize, data ) )
537 return FALSE;
538 DO_CONVERT:
539 if ( datasize >= sizeof(VS_VERSION_INFO_STRUCT16)
540 && datasize >= ((VS_VERSION_INFO_STRUCT16 *)data)->wLength
541 && !VersionInfoIs16( data ) )
543 /* convert resource from PE format to NE format */
544 ConvertVersionInfo32To16( (VS_VERSION_INFO_STRUCT32 *)data,
545 (VS_VERSION_INFO_STRUCT16 *)data );
548 return TRUE;
551 /***********************************************************************
552 * GetFileVersionInfoW [VERSION.@]
554 BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle,
555 DWORD datasize, LPVOID data )
557 DWORD len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL );
558 LPSTR fn = HeapAlloc( GetProcessHeap(), 0, len );
559 DWORD retv = TRUE;
561 WideCharToMultiByte( CP_ACP, 0, filename, -1, fn, len, NULL, NULL );
563 TRACE("(%s,%ld,size=%ld,data=%p)\n",
564 debugstr_w(filename), handle, datasize, data );
566 if(VERSION_GetFileVersionInfo_PE(fn, &handle, datasize, data))
567 goto END;
568 if(VERSION_GetFileVersionInfo_16(fn, &handle, datasize, data))
569 goto END;
571 if ( !GetFileResource16( fn, MAKEINTRESOURCEA(VS_FILE_INFO),
572 MAKEINTRESOURCEA(VS_VERSION_INFO),
573 handle, datasize, data ) )
574 retv = FALSE;
576 else if ( datasize >= sizeof(VS_VERSION_INFO_STRUCT16)
577 && datasize >= ((VS_VERSION_INFO_STRUCT16 *)data)->wLength
578 && VersionInfoIs16( data ) )
580 ERR("Cannot access NE resource in %s\n", debugstr_a(fn) );
581 retv = FALSE;
583 END:
584 HeapFree( GetProcessHeap(), 0, fn );
585 return retv;
589 /***********************************************************************
590 * VersionInfo16_FindChild [internal]
592 static VS_VERSION_INFO_STRUCT16 *VersionInfo16_FindChild( VS_VERSION_INFO_STRUCT16 *info,
593 LPCSTR szKey, UINT cbKey )
595 VS_VERSION_INFO_STRUCT16 *child = VersionInfo16_Children( info );
597 while ( (DWORD)child < (DWORD)info + info->wLength )
599 if ( !strncasecmp( child->szKey, szKey, cbKey ) )
600 return child;
602 if (!(child->wLength)) return NULL;
603 child = VersionInfo16_Next( child );
606 return NULL;
609 /***********************************************************************
610 * VersionInfo32_FindChild [internal]
612 static VS_VERSION_INFO_STRUCT32 *VersionInfo32_FindChild( VS_VERSION_INFO_STRUCT32 *info,
613 LPCWSTR szKey, UINT cbKey )
615 VS_VERSION_INFO_STRUCT32 *child = VersionInfo32_Children( info );
617 while ( (DWORD)child < (DWORD)info + info->wLength )
619 if ( !strncmpiW( child->szKey, szKey, cbKey ) )
620 return child;
622 child = VersionInfo32_Next( child );
625 return NULL;
628 /***********************************************************************
629 * VersionInfo16_QueryValue [internal]
631 * Gets a value from a 16-bit NE resource
633 DWORD WINAPI VersionInfo16_QueryValue( VS_VERSION_INFO_STRUCT16 *info, LPCSTR lpSubBlock,
634 LPVOID *lplpBuffer, UINT *puLen )
636 while ( *lpSubBlock )
638 /* Find next path component */
639 LPCSTR lpNextSlash;
640 for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
641 if ( *lpNextSlash == '\\' )
642 break;
644 /* Skip empty components */
645 if ( lpNextSlash == lpSubBlock )
647 lpSubBlock++;
648 continue;
651 /* We have a non-empty component: search info for key */
652 info = VersionInfo16_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
653 if ( !info ) return FALSE;
655 /* Skip path component */
656 lpSubBlock = lpNextSlash;
659 /* Return value */
660 *lplpBuffer = VersionInfo16_Value( info );
661 *puLen = info->wValueLength;
663 return TRUE;
666 /***********************************************************************
667 * VerQueryValueA [VERSION.@]
669 DWORD WINAPI VerQueryValueA( LPVOID pBlock, LPCSTR lpSubBlock,
670 LPVOID *lplpBuffer, UINT *puLen )
672 VS_VERSION_INFO_STRUCT16 *info = (VS_VERSION_INFO_STRUCT16 *)pBlock;
674 TRACE("(%p,%s,%p,%p)\n",
675 pBlock, debugstr_a(lpSubBlock), lplpBuffer, puLen );
677 if ( !VersionInfoIs16( info ) )
679 INT len;
680 LPWSTR wide_str;
681 DWORD give;
683 /* <lawson_whitney@juno.com> Feb 2001 */
684 /* AOL 5.0 does this, expecting to get this: */
685 len = MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, NULL, 0);
686 wide_str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
687 MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, wide_str, len);
689 give = VerQueryValueW(pBlock, wide_str, lplpBuffer, puLen);
690 HeapFree(GetProcessHeap(), 0, wide_str);
691 return give;
694 return VersionInfo16_QueryValue(info, lpSubBlock, lplpBuffer, puLen);
697 /***********************************************************************
698 * VerQueryValueW [VERSION.@]
700 DWORD WINAPI VerQueryValueW( LPVOID pBlock, LPCWSTR lpSubBlock,
701 LPVOID *lplpBuffer, UINT *puLen )
703 VS_VERSION_INFO_STRUCT32 *info = (VS_VERSION_INFO_STRUCT32 *)pBlock;
705 TRACE("(%p,%s,%p,%p)\n",
706 pBlock, debugstr_w(lpSubBlock), lplpBuffer, puLen );
708 if ( VersionInfoIs16( info ) )
710 DWORD ret;
711 int len = WideCharToMultiByte(CP_ACP, 0, lpSubBlock, -1, NULL, 0, NULL, NULL);
712 LPSTR lpSubBlockA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
713 if (!lpSubBlockA)
714 return FALSE;
715 WideCharToMultiByte(CP_ACP, 0, lpSubBlock, -1, lpSubBlockA, len, NULL, NULL);
716 ret = VersionInfo16_QueryValue(pBlock, lpSubBlockA, lplpBuffer, puLen);
717 HeapFree(GetProcessHeap(), 0, lpSubBlockA);
718 return ret;
721 while ( *lpSubBlock )
723 /* Find next path component */
724 LPCWSTR lpNextSlash;
725 for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
726 if ( *lpNextSlash == '\\' )
727 break;
729 /* Skip empty components */
730 if ( lpNextSlash == lpSubBlock )
732 lpSubBlock++;
733 continue;
736 /* We have a non-empty component: search info for key */
737 info = VersionInfo32_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
738 if ( !info ) return FALSE;
740 /* Skip path component */
741 lpSubBlock = lpNextSlash;
744 /* Return value */
745 *lplpBuffer = VersionInfo32_Value( info );
746 *puLen = info->wValueLength;
748 return TRUE;