Pelles C forum

C language => Beginner questions => Topic started by: DMac on August 16, 2025, 05:20:47 AM

Title: HRSRC returned by FindResource throws exception, has anyone encountered this?
Post by: DMac on August 16, 2025, 05:20:47 AM
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
Title: Re: HRSRC returned by FindResource throws exception, has anyone encountered this?
Post by: Marco on August 16, 2025, 10:53:15 AM
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
Title: Re: HRSRC returned by FindResource throws exception, has anyone encountered this?
Post by: TimoVJL on August 16, 2025, 01:23:19 PM
A test with Windows 7
Title: Re: HRSRC returned by FindResource throws exception, has anyone encountered this?
Post by: DMac on August 17, 2025, 04:36:56 AM
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