Free Pascal > Windows

Program unable to use resource from a .res file

(1/1)

440bx:
Hello,

I am using the latest version of Lazarus on Windows 7 SP1 64bit.  I should probably mention that I have one day of experience with FPC and Lazarus - IOW, I'm fairly clueless but trying to correct that problem.

I am compiling a program for 32bit execution (for now, after everything works right in 32bit, I'll tackle the 64bit version.)

The example consists of porting a very simple Windows API program which compiles and runs with Delphi 2 (yes, version 2) and performs as expected.

The program's resource file is produced by BRCC32.exe with the -w32 option to create a 32bit Windows resource file.

When Delphi 2 is handed the resulting .res file, it includes it in the executable and the resources, which include a menu and a dialog box are present and work as expected.

When using the same resource file with Lazarus or the command line FreePascal compiler, the menu and the dialog box are missing indicating that something went wrong with the resource file.

The file are as follows

1. resource.pas


--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  { resource IDs for the TextOut example                                      } {-----------------------------------------------------------------------------}INTERFACE{-----------------------------------------------------------------------------} const IDM_EXIT        = 900;  IDM_ABOUT       = 990; {-----------------------------------------------------------------------------}IMPLEMENTATION{-----------------------------------------------------------------------------} end. 
the resource file .rc which "includes" the above resource.pas is as follows:


--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#include "resource.pas" APPICON                 ICON                         "APPICON.ICO" APPMENU                 MENU  BEGIN    POPUP "&File"      BEGIN        MENUITEM "E&xit",                            IDM_EXIT      END     POPUP "&Help    "      BEGIN        MENUITEM "&About  TextOut ...",              IDM_ABOUT      END  END ABOUTBOX DIALOG 42, 20, 170, 90STYLE DS_MODALFRAME | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENUCAPTION "About TextOut"FONT 8, "MS Sans Serif"BEGIN  ICON              "APPICON", -1, 10, 10, 32, 32  LTEXT             "Win32 API Example - Functions", -1, 35, 10, 170, 10  LTEXT             "TextOut", -1, 35, 20, 170, 10  CTEXT             "Copyright \251 1997  You can copy it",-1, 1, 40, 170, 10  CTEXT             "All rights reserved.", -1, 1, 48, 170, 10  DEFPUSHBUTTON     "OK", IDOK, 60, 67, 50, 14END 
and the relevant bit of the program that uses the resource is as follows:

--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$APPTYPE        GUI} {$IFDEF FPC}  {$MODE       Delphi}  {$MODESWITCH ANSISTRINGS-}{$ENDIF} {$LONGSTRINGS    OFF}{$WRITEABLECONST ON}  {$R textout.RES} program _TextOut; uses Windows, Messages, Resource; 
Delphi 2 is happy with all of the above and produces what is show in the attachement that shows the program with its menu and its dialog box.

FPC and Lazarus, produce the program that has no menu and no dialog.


Cyrax:
Where is rest of the main program? Can you attach (sources only) your project files in this thread?

440bx:

--- Quote from: Cyrax on April 07, 2018, 11:57:25 pm ---Where is rest of the main program? Can you attach (sources only) your project files in this thread?

--- End quote ---

Most definitely can.  In the attached 7z archive are the source files, the .res file obtained with BRCC32.EXE and the executable obtained using Delphi 2.   I did this less than 5 minutes before typing this post and tested it to ensure it works as it should (using Delphi 2.0)

Thank you for your help :-)

John.

440bx:
Just in case someone else gets caught in this trap. 

The resource file was being overwritten with a new resource file of the same name by Lazarus.     

The solution is simple: do not use the same name for your resource file and the program because that's the name Lazarus uses, causing your resource file to be unceremoniously overwritten.   Call it something like "MyFunkyName.res" and it will be linked into the exe as expected and everything will work (provided that your resource IDs don't collide with those of Lazarus.)

Navigation

[0] Message Index

Go to full version