Hello,
I am a beginner in the use of resource files (.RC)
Here is my problem ; I would like to create an ini file which would be included in the executable, and which would be able to be modified in memory and then re-entered in the executable
I don't know how to do this or how to create a .RC file in the first place
I'm not sure how to create an RC file in the first place, but I'd like to know if someone can give me the basics so I can start programming.
Thanks in advance
Help with ressources files (.RC)
-
- Enthusiast
- Posts: 552
- Joined: Tue Oct 14, 2014 12:09 pm
Re: Help with ressources files (.RC)
I am pretty sure you have your reasons, because this is not the easiest way with PB.
Anyways, first you need a resource script file like:
Your PB-Code looks like that:
Don't forget to add the resource script file to Compiler | Compiler Options | Ressource
This example is very old and from the german forum, i guess,
HINT: There are also so-called Resource-Editors.
BTW: I have never tried and work still with the PB standard.
Happy coding and stay healthy.
Anyways, first you need a resource script file like:
Code: Select all
// ResDlg.rc
// Einfache AboutBox für PureBasic
// by TS-Soft
1000 DIALOG 0, 0, 109, 52
//LANGUAGE LANG_NEUTRAL, 0
//STYLE DS_CENTER | DS_MODALFRAME | DS_SETFONT | WS_BORDER | WS_DLGFRAME | WS_POPUP | WS_SYSMENU | WS_VISIBLE
//FONT 9, "Arial"
CAPTION "Über..."
BEGIN
CONTROL "PureBasic 3.94 Beta 4 Feel the ...Pure... Power", 1001, "Static", WS_GROUP | WS_VISIBLE, 19, 7, 102, 20
CONTROL "&Okay", 1002, "Button", BS_BOTTOM | BS_CENTER | BS_DEFPUSHBUTTON | BS_TOP | WS_MAXIMIZEBOX | WS_VISIBLE, 35, 30, 50, 15
END
Your PB-Code looks like that:
Code: Select all
; Simples Beispiel für eine AboutBox als Resource
; erstellt von TS-Soft
;/############################################################################
Procedure GetResDialog(DialogId, *DialogProcedure)
ProcedureReturn DialogBoxParam_(GetModuleHandle_(0), DialogId, 0, *DialogProcedure, 0)
EndProcedure
;/############################################################################
;/ Deklaration von Konstanten
; #define IDD_DLG1 1000
; #define IDC_LBL1 1001
; #define IDC_BTN1 1002
#IDD_DLG1 = 1000
#IDC_LBL1 = 1001
#IDC_BTN1 = 1002
; Beispiel einer DialogProcedure
Procedure DlgProc(hDlg, uMsg, wParam, lParam)
Select uMsg
Case #WM_INITDIALOG
MessageBeep_(#MB_ICONINFORMATION)
Case #WM_CLOSE
EndDialog_(hDlg, 0)
Case #WM_COMMAND
ID = wParam & $FFFF
Select ID
Case #IDC_BTN1
EndDialog_(hDlg, #IDC_BTN1) ; 1002 als Rückgabewert bei okay
EndSelect
EndSelect
EndProcedure
; Aufruf der DialogResource
Select GetResDialog(#IDD_DLG1, @DlgProc())
Case 0
MessageRequester("Dialog-Test", "Dialog wurde geschlossen")
Case #IDC_BTN1
MessageRequester("Dialog-Test", "Benutzer hat Okay gedrückt zum beenden")
EndSelect
This example is very old and from the german forum, i guess,
HINT: There are also so-called Resource-Editors.
BTW: I have never tried and work still with the PB standard.
Happy coding and stay healthy.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Help with ressources files (.RC)
Hi loulou2522
when an executable file is running, it's possible to read the data in resource (string, Datas etc.), but not to modify them.
You have to use the API :
error 5 means
When you close the main exe, the thread will update resources from main exe file.
In that case, you will have 2 exe files.
I do not try this.
in addition, the way to store the ini value depends of how to use them.
when an executable file is running, it's possible to read the data in resource (string, Datas etc.), but not to modify them.
You have to use the API :
But EndUpdateResource_() returns error 5 (via GetlastError), I did some tests.; BeginUpdateResourceW function
; https://learn.microsoft.com/en-us/windo ... eresourcew
; UpdateResourceW function
; https://learn.microsoft.com/en-us/windo ... eresourcew
; EndUpdateResourceW function
; https://learn.microsoft.com/en-us/windo ... eresourcew
error 5 means
BeginUpdateResource API indicates for its first parameter pFileName:ERROR_ACCESS_DENIED
5 (0x5)
Access is denied.
May be a solution will be to create a thread which will launch the main exe file, and and having sharing memory to store INI values.The binary file in which to update resources. An application must be able to obtain write-access to this file; the file referenced by pFileName cannot be currently executing. If pFileName does not specify a full path, the system searches for the file in the current directory.
When you close the main exe, the thread will update resources from main exe file.
In that case, you will have 2 exe files.
I do not try this.
in addition, the way to store the ini value depends of how to use them.
A+
Denis
Denis