| Laokoon (10) | ||
|
Hi, i have a problem with one of my functions. In one of the last lines: if (VerQueryValue(lpVI, tszVerStrName, &lpt, (PUINT)cbBufSize)){ name = ((LPTSTR)lpt); //wanna have the description - application name } This is never true. i cant image a solution for that. Can you plz help me?
best regards :-) | ||
|
Last edited on
|
||
| modoran (1245) | ||
Microsoft webpage for GetFileVersionInfoSizeEx() says:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa969435%28v=vs.85%29.aspx | ||
|
|
||
| Laokoon (10) | |
|
okay. hmm like this? GetFileVersionInfoExW(FILE_VER_GET_NEUTRAL|FILE_VER_GET_LOCALISED,(LPWSTR)szFile, NULL, dwLen, lpVI); befor the function: - szFile = 0x00371e30 L"C:\\Users\\Admin\\Documents\\Visual Studio 2012\\Projects\\MFCApplication1\\Debug\\MFCApplication1.exe" - dwLen = 1652 after this function: lpVI = 0x00372058 L"̸4" | |
|
|
|
| modoran (1245) | |
|
You have another error, you incorrectly use GlobalAlloc function. This returns a handle which later must be passed to GlobalLock()/GlobalUnlock() to obtain the memory pointer, it is not intended to cast the return value directly. And generally always use GetLastError after each function call to see where it fails. | |
|
|
|
| andywestken (1966) | |
|
@mordoran Actually, when GlobalAlloc is called with GPTR it is OK (and pretty comon practice) to just to cast the return as it's already a memory address. For example, the sample code in this MSDN entry shows GlobalAlloc + GPTR + cast... Formatted Date and Time Strings http://msdn.microsoft.com/en-us/library/cc194815.aspx You see, GPTR is GMEM_FIXED | GMEM_ZEROINIT. And GMEM_FIXED requests a fixed block of memory: i.e. the return value is a memory pointer. It's when you use GMEM_MOVEABLE that a handle (to a moveable block of memory) is returned and you are required to use GlobalLock to obtain an actual pointer. (Calling GlobalLock on a pointer returned when you GlobalAlloc with GPTR is benign: it just gives you the same--already fixed--address back.) Andy | |
|
Last edited on
|
|
| Laokoon (10) | |
|
Thanks for the answers. The error-Code is 1813 (from GetLastError)), it means, that the ressource was not found. But there have to be a ressource. The error-Code is set here: if (VerQueryValue(lpVI, tszVerStrName, &lpt, (PUINT)cbBufSize)) Does anyone have an advide? best regards | |
|
|
|
| andywestken (1966) | |
|
#1 Open the binary and check the resource looks as expected #2 Use either GetFileVersionInfoSize + GetFileVersionInfo or GetFileVersionInfoSizeEx + GetFileVersionInfoEx i.e. don't mix Ex and non-Ex (just in case...) #3 Are you using the MUI mechanism? If not, the right flag value might be none (i.e. 0) (the non-Ex prob calls the Ex version with no flags?) | |
|
Last edited on
|
|
| Laokoon (10) | |||
|
Hi, thanks for the answer. i changed my code. it looks like this now: ~see code below But its still not working and i really dont know why... here are a few debug-values:
Here's now the code:
Who can solve this problem? BE my hero lol :D | |||
|
Last edited on
|
|||
| modoran (1245) | ||
This seems like bad cast to me:
after you declared cbBufSize as UINT initialized with 0. Try this: VerQueryValue(lpVI, tszVerStrName, &lpt, &cbBufSize)
| ||
|
|
||
| Laokoon (10) | |
|
this doesnt solve my problem. cdBufSize is 0 at this Moment. The Error still exists. | |
|
|
|
| modoran (1245) | ||
It is 0 at the moment, but its value will be changed after calling win32 function VerQueryValue..
| ||
|
|
||