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
33 #include "wine/winuser16.h"
34 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ver
);
40 /******************************************************************************
42 * This function will print via standard TRACE, debug info regarding
43 * the file info structure vffi.
44 * 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
45 * Added this function to clean up the code.
47 *****************************************************************************/
48 static void print_vffi_debug(const VS_FIXEDFILEINFO
*vffi
)
50 BOOL versioned_printer
= FALSE
;
52 if((vffi
->dwFileType
== VFT_DLL
) || (vffi
->dwFileType
== VFT_DRV
))
54 if(vffi
->dwFileSubtype
== VFT2_DRV_VERSIONED_PRINTER
)
55 /* this is documented for newer w2k Drivers and up */
56 versioned_printer
= TRUE
;
57 else if( (vffi
->dwFileSubtype
== VFT2_DRV_PRINTER
) &&
58 (vffi
->dwFileVersionMS
!= vffi
->dwProductVersionMS
) &&
59 (vffi
->dwFileVersionMS
> 0) &&
60 (vffi
->dwFileVersionMS
<= 3) )
61 /* found this on NT 3.51, NT4.0 and old w2k Drivers */
62 versioned_printer
= TRUE
;
65 TRACE("structversion=%u.%u, ",
66 HIWORD(vffi
->dwStrucVersion
),LOWORD(vffi
->dwStrucVersion
));
69 WORD mode
= LOWORD(vffi
->dwFileVersionMS
);
70 WORD ver_rev
= HIWORD(vffi
->dwFileVersionLS
);
71 TRACE("fileversion=%u.%u.%u.%u (%s.major.minor.release), ",
72 (vffi
->dwFileVersionMS
),
73 HIBYTE(ver_rev
), LOBYTE(ver_rev
), LOWORD(vffi
->dwFileVersionLS
),
74 (mode
== 3) ? "Usermode" : ((mode
<= 2) ? "Kernelmode" : "?") );
78 TRACE("fileversion=%u.%u.%u.%u, ",
79 HIWORD(vffi
->dwFileVersionMS
),LOWORD(vffi
->dwFileVersionMS
),
80 HIWORD(vffi
->dwFileVersionLS
),LOWORD(vffi
->dwFileVersionLS
));
82 TRACE("productversion=%u.%u.%u.%u\n",
83 HIWORD(vffi
->dwProductVersionMS
),LOWORD(vffi
->dwProductVersionMS
),
84 HIWORD(vffi
->dwProductVersionLS
),LOWORD(vffi
->dwProductVersionLS
));
86 TRACE("flagmask=0x%x, flags=0x%x %s%s%s%s%s%s\n",
87 vffi
->dwFileFlagsMask
, vffi
->dwFileFlags
,
88 (vffi
->dwFileFlags
& VS_FF_DEBUG
) ? "DEBUG," : "",
89 (vffi
->dwFileFlags
& VS_FF_PRERELEASE
) ? "PRERELEASE," : "",
90 (vffi
->dwFileFlags
& VS_FF_PATCHED
) ? "PATCHED," : "",
91 (vffi
->dwFileFlags
& VS_FF_PRIVATEBUILD
) ? "PRIVATEBUILD," : "",
92 (vffi
->dwFileFlags
& VS_FF_INFOINFERRED
) ? "INFOINFERRED," : "",
93 (vffi
->dwFileFlags
& VS_FF_SPECIALBUILD
) ? "SPECIALBUILD," : "");
97 TRACE("OS=0x%x.0x%x ", HIWORD(vffi
->dwFileOS
), LOWORD(vffi
->dwFileOS
));
99 switch (vffi
->dwFileOS
&0xFFFF0000)
101 case VOS_DOS
:TRACE("DOS,");break;
102 case VOS_OS216
:TRACE("OS/2-16,");break;
103 case VOS_OS232
:TRACE("OS/2-32,");break;
104 case VOS_NT
:TRACE("NT,");break;
107 TRACE("UNKNOWN(0x%x),",vffi
->dwFileOS
&0xFFFF0000);break;
110 switch (LOWORD(vffi
->dwFileOS
))
112 case VOS__BASE
:TRACE("BASE");break;
113 case VOS__WINDOWS16
:TRACE("WIN16");break;
114 case VOS__WINDOWS32
:TRACE("WIN32");break;
115 case VOS__PM16
:TRACE("PM16");break;
116 case VOS__PM32
:TRACE("PM32");break;
118 TRACE("UNKNOWN(0x%x)",LOWORD(vffi
->dwFileOS
));break;
123 switch (vffi
->dwFileType
)
125 case VFT_APP
:TRACE("filetype=APP");break;
127 TRACE("filetype=DLL");
128 if(vffi
->dwFileSubtype
!= 0)
130 if(versioned_printer
) /* NT3.x/NT4.0 or old w2k Driver */
132 TRACE(" (subtype=0x%x)", vffi
->dwFileSubtype
);
136 TRACE("filetype=DRV,");
137 switch(vffi
->dwFileSubtype
)
139 case VFT2_DRV_PRINTER
:TRACE("PRINTER");break;
140 case VFT2_DRV_KEYBOARD
:TRACE("KEYBOARD");break;
141 case VFT2_DRV_LANGUAGE
:TRACE("LANGUAGE");break;
142 case VFT2_DRV_DISPLAY
:TRACE("DISPLAY");break;
143 case VFT2_DRV_MOUSE
:TRACE("MOUSE");break;
144 case VFT2_DRV_NETWORK
:TRACE("NETWORK");break;
145 case VFT2_DRV_SYSTEM
:TRACE("SYSTEM");break;
146 case VFT2_DRV_INSTALLABLE
:TRACE("INSTALLABLE");break;
147 case VFT2_DRV_SOUND
:TRACE("SOUND");break;
148 case VFT2_DRV_COMM
:TRACE("COMM");break;
149 case VFT2_DRV_INPUTMETHOD
:TRACE("INPUTMETHOD");break;
150 case VFT2_DRV_VERSIONED_PRINTER
:TRACE("VERSIONED_PRINTER");break;
153 TRACE("UNKNOWN(0x%x)",vffi
->dwFileSubtype
);break;
157 TRACE("filetype=FONT,");
158 switch (vffi
->dwFileSubtype
)
160 case VFT2_FONT_RASTER
:TRACE("RASTER");break;
161 case VFT2_FONT_VECTOR
:TRACE("VECTOR");break;
162 case VFT2_FONT_TRUETYPE
:TRACE("TRUETYPE");break;
163 default:TRACE("UNKNOWN(0x%x)",vffi
->dwFileSubtype
);break;
166 case VFT_VXD
:TRACE("filetype=VXD");break;
167 case VFT_STATIC_LIB
:TRACE("filetype=STATIC_LIB");break;
170 TRACE("filetype=Unknown(0x%x)",vffi
->dwFileType
);break;
174 TRACE("filedate=0x%x.0x%x\n",vffi
->dwFileDateMS
,vffi
->dwFileDateLS
);
177 /***********************************************************************
178 * Version Info Structure
186 #if 0 /* variable length structure */
190 VS_VERSION_INFO_STRUCT16 Children
[];
192 } VS_VERSION_INFO_STRUCT16
;
200 #if 0 /* variable length structure */
204 VS_VERSION_INFO_STRUCT32 Children
[];
206 } VS_VERSION_INFO_STRUCT32
;
208 #define VersionInfoIs16( ver ) \
209 ( ((const VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
211 #define DWORD_ALIGN( base, ptr ) \
212 ( (LPBYTE)(base) + ((((LPBYTE)(ptr) - (LPBYTE)(base)) + 3) & ~3) )
214 #define VersionInfo16_Value( ver ) \
215 DWORD_ALIGN( (ver), (ver)->szKey + strlen((ver)->szKey) + 1 )
216 #define VersionInfo32_Value( ver ) \
217 DWORD_ALIGN( (ver), (ver)->szKey + strlenW((ver)->szKey) + 1 )
219 #define VersionInfo16_Children( ver ) \
220 (const VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
221 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
222 #define VersionInfo32_Children( ver ) \
223 (const VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
224 ( ( (ver)->wValueLength * \
225 ((ver)->wType? 2 : 1) + 3 ) & ~3 ) )
227 #define VersionInfo16_Next( ver ) \
228 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
229 #define VersionInfo32_Next( ver ) \
230 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
232 /***********************************************************************
233 * VERSION_GetFileVersionInfo_PE [internal]
235 * NOTE: returns size of the PE VERSION resource or 0xFFFFFFFF
236 * in the case the file is a PE module, but VERSION_INFO not found.
238 static DWORD
VERSION_GetFileVersionInfo_PE( LPCWSTR filename
, DWORD datasize
, LPVOID data
)
240 const VS_FIXEDFILEINFO
*vffi
;
247 TRACE("%s\n", debugstr_w(filename
));
249 if (!GetModuleHandleExW(0, filename
, &hModule
))
250 hModule
= LoadLibraryExW(filename
, 0, LOAD_LIBRARY_AS_DATAFILE
);
254 WARN("Could not load %s\n", debugstr_w(filename
));
258 hRsrc
= FindResourceW(hModule
,
259 MAKEINTRESOURCEW(VS_VERSION_INFO
),
260 MAKEINTRESOURCEW(VS_FILE_INFO
));
263 WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_w(filename
));
264 FreeLibrary(hModule
);
267 len
= SizeofResource(hModule
, hRsrc
);
268 hMem
= LoadResource(hModule
, hRsrc
);
271 WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_w(filename
));
272 FreeLibrary(hModule
);
275 buf
= LockResource(hMem
);
277 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32
*)buf
);
279 if ( vffi
->dwSignature
!= VS_FFI_SIGNATURE
)
281 WARN("vffi->dwSignature is 0x%08x, but not 0x%08lx!\n",
282 vffi
->dwSignature
, VS_FFI_SIGNATURE
);
288 print_vffi_debug( vffi
);
293 len
= datasize
; /* truncate data */
295 memcpy(data
, buf
, len
);
301 FreeLibrary(hModule
);
306 /***********************************************************************
307 * VERSION_GetFileVersionInfo_16 [internal]
309 * NOTE: returns size of the 16-bit VERSION resource or 0xFFFFFFFF
310 * in the case the file exists, but VERSION_INFO not found.
312 static DWORD
VERSION_GetFileVersionInfo_16( LPCSTR filename
, DWORD datasize
, LPVOID data
)
314 const VS_FIXEDFILEINFO
*vffi
;
320 char dllname
[20], owner
[20], *p
;
321 const char *basename
;
322 BOOL is_builtin
= FALSE
;
324 TRACE("%s\n", debugstr_a(filename
));
326 /* strip path information */
329 if (basename
[0] && basename
[1] == ':') basename
+= 2; /* strip drive specification */
330 if ((p
= strrchr( basename
, '\\' ))) basename
= p
+ 1;
331 if ((p
= strrchr( basename
, '/' ))) basename
= p
+ 1;
333 if (strlen(basename
) < sizeof(dllname
)-4)
337 strcpy( dllname
, basename
);
338 p
= strrchr( dllname
, '.' );
339 if (!p
) strcat( dllname
, ".dll" );
340 for (p
= dllname
; *p
; p
++) if (*p
>= 'A' && *p
<= 'Z') *p
+= 32;
342 if (wine_dll_get_owner( dllname
, owner
, sizeof(owner
), &file_exists
) == 0)
346 /* first try without loading a 16-bit module */
350 len
= GetFileResourceSize16( filename
,
351 MAKEINTRESOURCEA(VS_FILE_INFO
),
352 MAKEINTRESOURCEA(VS_VERSION_INFO
),
356 if (!data
) return len
;
358 len
= GetFileResource16( filename
,
359 MAKEINTRESOURCEA(VS_FILE_INFO
),
360 MAKEINTRESOURCEA(VS_VERSION_INFO
),
361 offset
, datasize
, data
);
364 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16
*)data
);
366 if ( vffi
->dwSignature
== VS_FFI_SIGNATURE
)
368 if ( ((VS_VERSION_INFO_STRUCT16
*)data
)->wLength
< len
)
369 len
= ((VS_VERSION_INFO_STRUCT16
*)data
)->wLength
;
372 print_vffi_debug( vffi
);
379 /* this might be a builtin 16-bit module */
380 hModule
= LoadLibrary16(filename
);
383 WARN("Could not load %s\n", debugstr_a(filename
));
384 if (hModule
== ERROR_BAD_FORMAT
)
389 hRsrc
= FindResource16(hModule
,
390 MAKEINTRESOURCEA(VS_VERSION_INFO
),
391 MAKEINTRESOURCEA(VS_FILE_INFO
));
394 WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_a(filename
));
395 FreeLibrary16(hModule
);
398 len
= SizeofResource16(hModule
, hRsrc
);
399 hMem
= LoadResource16(hModule
, hRsrc
);
402 WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_a(filename
));
403 FreeLibrary16(hModule
);
406 buf
= LockResource16(hMem
);
408 if(!VersionInfoIs16(buf
))
414 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16
*)buf
);
416 if ( vffi
->dwSignature
!= VS_FFI_SIGNATURE
)
418 WARN("vffi->dwSignature is 0x%08x, but not 0x%08lx!\n",
419 vffi
->dwSignature
, VS_FFI_SIGNATURE
);
425 print_vffi_debug( vffi
);
430 len
= datasize
; /* truncate data */
432 memcpy(data
, buf
, len
);
437 FreeResource16(hMem
);
438 FreeLibrary16(hModule
);
443 /***********************************************************************
444 * GetFileVersionInfoSizeW [VERSION.@]
446 DWORD WINAPI
GetFileVersionInfoSizeW( LPCWSTR filename
, LPDWORD handle
)
450 TRACE("(%s,%p)\n", debugstr_w(filename
), handle
);
452 if (handle
) *handle
= 0;
456 SetLastError(ERROR_INVALID_PARAMETER
);
461 SetLastError(ERROR_BAD_PATHNAME
);
465 len
= VERSION_GetFileVersionInfo_PE(filename
, 0, NULL
);
466 /* 0xFFFFFFFF means: file is a PE module, but VERSION_INFO not found */
467 if(len
== 0xFFFFFFFF)
469 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
477 len
= WideCharToMultiByte( CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
478 filenameA
= HeapAlloc( GetProcessHeap(), 0, len
);
479 WideCharToMultiByte( CP_ACP
, 0, filename
, -1, filenameA
, len
, NULL
, NULL
);
481 len
= VERSION_GetFileVersionInfo_16(filenameA
, 0, NULL
);
482 HeapFree( GetProcessHeap(), 0, filenameA
);
483 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
486 SetLastError(ERROR_FILE_NOT_FOUND
);
489 if (len
== 0xFFFFFFFF)
491 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
495 /* We have a 16bit resource.
497 * XP/W2K/W2K3 uses a buffer which is more than the actual needed space:
499 * (info->wLength - sizeof(VS_FIXEDFILEINFO)) * 4
501 * This extra buffer is used for ANSI to Unicode conversions in W-Calls.
502 * info->wLength should be the same as len. Currently it isn't but that
503 * doesn't seem to be a problem (len is bigger than info->wLength).
505 len
= (len
- sizeof(VS_FIXEDFILEINFO
)) * 4;
509 /* We have a 32bit resource.
511 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
512 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
521 /***********************************************************************
522 * GetFileVersionInfoSizeA [VERSION.@]
524 DWORD WINAPI
GetFileVersionInfoSizeA( LPCSTR filename
, LPDWORD handle
)
526 UNICODE_STRING filenameW
;
529 TRACE("(%s,%p)\n", debugstr_a(filename
), handle
);
532 RtlCreateUnicodeStringFromAsciiz(&filenameW
, filename
);
534 filenameW
.Buffer
= NULL
;
536 retval
= GetFileVersionInfoSizeW(filenameW
.Buffer
, handle
);
538 RtlFreeUnicodeString(&filenameW
);
543 /***********************************************************************
544 * GetFileVersionInfoW [VERSION.@]
546 BOOL WINAPI
GetFileVersionInfoW( LPCWSTR filename
, DWORD handle
,
547 DWORD datasize
, LPVOID data
)
550 VS_VERSION_INFO_STRUCT32
* vvis
= (VS_VERSION_INFO_STRUCT32
*)data
;
552 TRACE("(%s,%d,size=%d,data=%p)\n",
553 debugstr_w(filename
), handle
, datasize
, data
);
557 SetLastError(ERROR_INVALID_DATA
);
560 len
= VERSION_GetFileVersionInfo_PE(filename
, datasize
, data
);
561 /* 0xFFFFFFFF means: file is a PE module, but VERSION_INFO not found */
562 if (len
== 0xFFFFFFFF)
564 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
572 len
= WideCharToMultiByte( CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
573 filenameA
= HeapAlloc( GetProcessHeap(), 0, len
);
574 WideCharToMultiByte( CP_ACP
, 0, filename
, -1, filenameA
, len
, NULL
, NULL
);
576 len
= VERSION_GetFileVersionInfo_16(filenameA
, datasize
, data
);
577 HeapFree( GetProcessHeap(), 0, filenameA
);
578 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
579 if (!len
|| len
== 0xFFFFFFFF)
581 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
584 /* We have a 16bit resource. */
588 static const char signature
[] = "FE2X";
589 DWORD bufsize
= vvis
->wLength
+ strlen(signature
);
592 /* We have a 32bit resource.
594 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
595 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
598 /* information is truncated to datasize bytes */
599 if (datasize
>= bufsize
)
601 convbuf
= datasize
- vvis
->wLength
;
602 memcpy( ((char*)(data
))+vvis
->wLength
, signature
, convbuf
> 4 ? 4 : convbuf
);
610 /***********************************************************************
611 * GetFileVersionInfoA [VERSION.@]
613 BOOL WINAPI
GetFileVersionInfoA( LPCSTR filename
, DWORD handle
,
614 DWORD datasize
, LPVOID data
)
616 UNICODE_STRING filenameW
;
619 TRACE("(%s,%d,size=%d,data=%p)\n",
620 debugstr_a(filename
), handle
, datasize
, data
);
623 RtlCreateUnicodeStringFromAsciiz(&filenameW
, filename
);
625 filenameW
.Buffer
= NULL
;
627 retval
= GetFileVersionInfoW(filenameW
.Buffer
, handle
, datasize
, data
);
629 RtlFreeUnicodeString(&filenameW
);
634 /***********************************************************************
635 * VersionInfo16_FindChild [internal]
637 static const VS_VERSION_INFO_STRUCT16
*VersionInfo16_FindChild( const VS_VERSION_INFO_STRUCT16
*info
,
638 LPCSTR szKey
, UINT cbKey
)
640 const VS_VERSION_INFO_STRUCT16
*child
= VersionInfo16_Children( info
);
642 while ((char *)child
< (char *)info
+ info
->wLength
)
644 if (!strncasecmp( child
->szKey
, szKey
, cbKey
) && !child
->szKey
[cbKey
])
647 if (!(child
->wLength
)) return NULL
;
648 child
= VersionInfo16_Next( child
);
654 /***********************************************************************
655 * VersionInfo32_FindChild [internal]
657 static const VS_VERSION_INFO_STRUCT32
*VersionInfo32_FindChild( const VS_VERSION_INFO_STRUCT32
*info
,
658 LPCWSTR szKey
, UINT cbKey
)
660 const VS_VERSION_INFO_STRUCT32
*child
= VersionInfo32_Children( info
);
662 while ((char *)child
< (char *)info
+ info
->wLength
)
664 if (!strncmpiW( child
->szKey
, szKey
, cbKey
) && !child
->szKey
[cbKey
])
667 if (!(child
->wLength
)) return NULL
;
668 child
= VersionInfo32_Next( child
);
674 /***********************************************************************
675 * VersionInfo16_QueryValue [internal]
677 * Gets a value from a 16-bit NE resource
679 static BOOL
VersionInfo16_QueryValue( const VS_VERSION_INFO_STRUCT16
*info
, LPCSTR lpSubBlock
,
680 LPVOID
*lplpBuffer
, UINT
*puLen
)
682 while ( *lpSubBlock
)
684 /* Find next path component */
686 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
687 if ( *lpNextSlash
== '\\' )
690 /* Skip empty components */
691 if ( lpNextSlash
== lpSubBlock
)
697 /* We have a non-empty component: search info for key */
698 info
= VersionInfo16_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
701 if (puLen
) *puLen
= 0 ;
702 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND
);
706 /* Skip path component */
707 lpSubBlock
= lpNextSlash
;
711 *lplpBuffer
= VersionInfo16_Value( info
);
713 *puLen
= info
->wValueLength
;
718 /***********************************************************************
719 * VersionInfo32_QueryValue [internal]
721 * Gets a value from a 32-bit PE resource
723 static BOOL
VersionInfo32_QueryValue( const VS_VERSION_INFO_STRUCT32
*info
, LPCWSTR lpSubBlock
,
724 LPVOID
*lplpBuffer
, UINT
*puLen
)
726 TRACE("lpSubBlock : (%s)\n", debugstr_w(lpSubBlock
));
728 while ( *lpSubBlock
)
730 /* Find next path component */
732 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
733 if ( *lpNextSlash
== '\\' )
736 /* Skip empty components */
737 if ( lpNextSlash
== lpSubBlock
)
743 /* We have a non-empty component: search info for key */
744 info
= VersionInfo32_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
747 if (puLen
) *puLen
= 0 ;
748 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND
);
752 /* Skip path component */
753 lpSubBlock
= lpNextSlash
;
757 *lplpBuffer
= VersionInfo32_Value( info
);
759 *puLen
= info
->wValueLength
;
764 /***********************************************************************
765 * VerQueryValueA [VERSION.@]
767 BOOL WINAPI
VerQueryValueA( LPCVOID pBlock
, LPCSTR lpSubBlock
,
768 LPVOID
*lplpBuffer
, PUINT puLen
)
770 static const char rootA
[] = "\\";
771 static const char varfileinfoA
[] = "\\VarFileInfo\\Translation";
772 const VS_VERSION_INFO_STRUCT16
*info
= (const VS_VERSION_INFO_STRUCT16
*)pBlock
;
774 TRACE("(%p,%s,%p,%p)\n",
775 pBlock
, debugstr_a(lpSubBlock
), lplpBuffer
, puLen
);
780 if (lpSubBlock
== NULL
|| lpSubBlock
[0] == '\0')
783 if ( !VersionInfoIs16( info
) )
789 len
= MultiByteToWideChar(CP_ACP
, 0, lpSubBlock
, -1, NULL
, 0);
790 lpSubBlockW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
795 MultiByteToWideChar(CP_ACP
, 0, lpSubBlock
, -1, lpSubBlockW
, len
);
797 ret
= VersionInfo32_QueryValue(pBlock
, lpSubBlockW
, lplpBuffer
, puLen
);
799 HeapFree(GetProcessHeap(), 0, lpSubBlockW
);
801 if (ret
&& strcasecmp( lpSubBlock
, rootA
) && strcasecmp( lpSubBlock
, varfileinfoA
))
803 /* Set lpBuffer so it points to the 'empty' area where we store
804 * the converted strings
806 LPSTR lpBufferA
= (LPSTR
)pBlock
+ info
->wLength
+ 4;
807 DWORD pos
= (LPCSTR
)*lplpBuffer
- (LPCSTR
)pBlock
;
809 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)*lplpBuffer
, -1,
810 lpBufferA
+ pos
, info
->wLength
- pos
, NULL
, NULL
);
811 *lplpBuffer
= lpBufferA
+ pos
;
817 return VersionInfo16_QueryValue(info
, lpSubBlock
, lplpBuffer
, puLen
);
820 /***********************************************************************
821 * VerQueryValueW [VERSION.@]
823 BOOL WINAPI
VerQueryValueW( LPCVOID pBlock
, LPCWSTR lpSubBlock
,
824 LPVOID
*lplpBuffer
, PUINT puLen
)
826 static const WCHAR nullW
[] = { 0 };
827 static const WCHAR rootW
[] = { '\\', 0 };
828 static const WCHAR varfileinfoW
[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
829 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
831 const VS_VERSION_INFO_STRUCT32
*info
= (const VS_VERSION_INFO_STRUCT32
*)pBlock
;
833 TRACE("(%p,%s,%p,%p)\n",
834 pBlock
, debugstr_w(lpSubBlock
), lplpBuffer
, puLen
);
839 if (lpSubBlock
== NULL
|| lpSubBlock
[0] == nullW
[0])
842 if ( VersionInfoIs16( info
) )
848 len
= WideCharToMultiByte(CP_ACP
, 0, lpSubBlock
, -1, NULL
, 0, NULL
, NULL
);
849 lpSubBlockA
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
854 WideCharToMultiByte(CP_ACP
, 0, lpSubBlock
, -1, lpSubBlockA
, len
, NULL
, NULL
);
856 ret
= VersionInfo16_QueryValue(pBlock
, lpSubBlockA
, lplpBuffer
, puLen
);
858 HeapFree(GetProcessHeap(), 0, lpSubBlockA
);
860 if (ret
&& strcmpiW( lpSubBlock
, rootW
) && strcmpiW( lpSubBlock
, varfileinfoW
))
862 /* Set lpBuffer so it points to the 'empty' area where we store
863 * the converted strings
865 LPWSTR lpBufferW
= (LPWSTR
)((LPSTR
)pBlock
+ info
->wLength
);
866 DWORD pos
= (LPCSTR
)*lplpBuffer
- (LPCSTR
)pBlock
;
867 DWORD max
= (info
->wLength
- sizeof(VS_FIXEDFILEINFO
)) * 4 - info
->wLength
;
869 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)*lplpBuffer
, -1,
870 lpBufferW
+ pos
, max
/sizeof(WCHAR
) - pos
);
871 *lplpBuffer
= lpBufferW
+ pos
;
877 return VersionInfo32_QueryValue(info
, lpSubBlock
, lplpBuffer
, puLen
);