Options for linking custom data as a resource?

If you add a JSON file to a Clarion project, it gets linked under IMAGE, as can be seen in PE Explorer.

Using the resource compiler you can put it in another section such as RC Data, and that’s pretty simple to do.

I thought I heard of another way to do it, though. Wasn’t there a way to use an additional PRJ or something like that, or does that still put the resource under IMAGE? I’m trying to avoid the extra RC step, if possible.

Thanks.

Hi Jeff, apologies in advance but I have no idea how to do it, but I pasted your question into the Google and it gave me an AI generated response that looked pretty promising - to me, who has no idea!

I repeated the query to try and get a link to post here and the response was different and looked less helpful. So, here is the original response. I don’t know if it is rubbish, but you should be able to tell pretty quickly, so it won’t waste too much of your time…

Apparently this answer from Google doesn’t work for Clarion, so I have removed it.

Although I appreciate the effort of googling the issue, which I had also done, the problem is that this doesn’t work and should not be on Clarionhub as a solution. Thank you for your kindness, all the same.

Clarion doesn’t run the resource compiler. Maybe it can be setup to do so, but it does not happen solely by existence of the .rc file in the project. If it can be setup to do so, instructions should go along with the above. Didn’t work for me when I was trying to get it to work.

If you run the compiler yourself, and attach the .res, then it works fine. I was looking to avoid that step. But now that I’ve done the work of setting it up, it’s really not that much of a bother to run the RC when needed.

Thanks again.

Jeff is correct — Clarion does not automatically run the resource compiler on .rc files. However, you can fully automate this using the .cwproj build system.

Here’s a setup that works:


1. Create your .rc file

IDR_MY_JSON  RCDATA  "data.json"

2. Add a PreBuildEvent to your .cwproj

In the IDE, open the project properties and add this to the Pre-build event:

"C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x86\rc.exe" /fo "$(MSBuildProjectDirectory)\genfiles\data.res" "$(MSBuildProjectDirectory)\data.rc" & exit 0

3. Add the .res file to the linker

Either add the .res file via Libraries, Objects and Resource Files, or edit the .cwproj and include:

<ItemGroup>
  <Library Include="genfiles\data.res" />
</ItemGroup>

Notes

  • rc.exe ships with the Windows SDK (path may vary; note the x86 version)
  • The PreBuildEvent runs before Clarion’s compile and link step
  • The .res file will be ready when the linker runs
  • The & exit 0 is required because rc.exe can return a non-zero exit code even on success, which MSBuild would otherwise treat as a failure

Tested and working in Clarion 11.1

Apologies — my earlier post was incorrect. I tested whether the JSON string appeared in the raw EXE bytes, which it did, but I didn’t actually test the Windows API call. When tested properly using FindResource, it returns 0 (not found).

The reason, I think: Clarion’s TopSpeed linker uses its own proprietary .RSC resource format and does not process the Windows .res resource section. The string ends up as raw linked bytes in the EXE, not in the PE resource table that FindResource reads from.

So the original AI answer and my post are both wrong on the final step. The rc.exe + PreBuildEvent approach compiles correctly, but Clarion’s linker cannot merge the result into a proper Windows resource section regardless of how you attach the .res.

Sorry for the noise.

Following up on this thread — I managed to get resources embedded into a Clarion EXE without needing to manually run anything.

The key issue is that Clarion’s TopSpeed linker does not properly merge standard Windows .res files into the PE resource section. You can pass a .res via PRAGMA('link(...)') or as a <Library> item, and it appears to be accepted, but the resource section is not built in a way that the WinAPI can use. That’s why FindResource() fails even though the data may appear to be present in the EXE.


Working solution: post-build injection

The approach that works reliably is to inject the resource after the EXE has been built.

Using Resource Hacker CLI:

Install:

winget install AngusJohnson.ResourceHacker

Then add this to your Post-build event in the Clarion project:

"C:\Program Files (x86)\Resource Hacker\ResourceHacker.exe" ^ -open "$(MSBuildProjectDirectory)\build\MyApp.exe" ^ -save "$(MSBuildProjectDirectory)\build\MyApp.exe" ^ -action addoverwrite ^ -resource "$(MSBuildProjectDirectory)\mydata.json" ^ -mask RCDATA,IDR_MY_DATA,0 ^ -log NUL

Notes

  • No .rc file is required — Resource Hacker embeds the file directly as an RCDATA resource
  • The resource is added to a proper .rsrc section, so FindResource() works as expected
  • $(MSBuildProjectDirectory) survives Clarion IDE rewrites, so it’s safe to use in build events

This keeps everything fully automated while working around the linker limitation.

Thanks a lot, Mark. That would be very good for a single dev situation. Not sure it would work out for a team and CICD.

Committing the compiled resource as needed so that the .res can be linked in as-is will probably work out alright. But it’s good to know about this alternative.

Thanks again