HRSRC returned by FindResource throws exception, has anyone encountered this?

Started by DMac, August 16, 2025, 05:20:47 AM

Previous topic - Next topic

DMac

I have an application that I am updating with the latest Pelles C (version 13).

Unfortunately my GetVersionInfo() function does not work when compiled with version 13.

HRSRC hVersion = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);

    if (hVersion != NULL) //<-- This line causes an Access Violation

In my Resource file I have the following:

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,3,2,0
PRODUCTVERSION 1,3,2,0
FILEFLAGSMASK 0x3F
FILEFLAGS 0x0
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
{
  BLOCK "StringFileInfo"
  {
    BLOCK "040904B0"
    {
      VALUE "FileVersion", "1.3.2.0\0"
      VALUE "LegalCopyright", "2014 - 2025\0"
      VALUE "ProductName", "Instrument Snapshot\0"
      VALUE "ProductVersion", "1.3.2.0\0"
    }
  }
  BLOCK "VarFileInfo"
  {
    VALUE "Translation", 0x409, 0x4B0
  }
}

So I know it's there.  Has anyone encountered this?  I guess something has changed but I have no idea what.
Does anyone know of another way to get the version info?

--DMAC
No one cares how much you know,
until they know how much you care.

Marco

Hi DMac,

I tried running your code on my PC and didn't encounter any errors. Pelles C (v13) compiled and ran the application test without any issues. I tried all the possible optimisation options. Perhaps the problem lies elsewhere in the code and is affecting that instruction somehow.

Have you also tried using the 'FindResourceEx' function?

Marco

TimoVJL

May the source be with you

DMac

Thanks for the example test project Timo.

After testing and looking at the code and comparing it to mine.  I began to suspect that the issue was was possibly related to my use of VLAs.  I tried debugging with optimizations off and the access violation would happen further down in the code.  I then swapped in your example code and it performed correctly even with optimizations on. 

Moving on to the next perplexing bug...

--DMac

No one cares how much you know,
until they know how much you care.