Add some text in the exe file

Moderator: Rathinagiri

User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Add some text in the exe file

Post by hmgchang »

Hola Masters,

I hava an .exe file compiled by hmg and a small .ini text file for the program configuration.
My question is can I save the content of the .ini file to the end of the .exe file,
so that i only need one .exe file.
Pls advise on how to do it...

Thks n Rgds

hmg-Chang
Just Hmg It !
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Add some text in the exe file

Post by bpd2000 »

.ini file can be embed in .exe and extrected as and when required
Sample may be useful to you
Attachments
restore from resource.zip
(1.45 MiB) Downloaded 223 times
BPD
Convert Dream into Reality through HMG
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Add some text in the exe file

Post by hmgchang »

Thank you very much...
I will meditate on it....
Just Hmg It !
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Add some text in the exe file

Post by hmgchang »

The sample is to RESTORE the file from the an .exe file that i need to.
But i don't know how to attach it to the .exe file at the first.
Pls be kind to advise ....
Thks n Rgds
hmg-Chang
Just Hmg It !
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Add some text in the exe file

Post by bpd2000 »

hmgchang wrote: Tue Mar 16, 2021 10:08 am The sample is to RESTORE the file from the an .exe file that i need to.
But i don't know how to attach it to the .exe file at the first.
Pls be kind to advise ....
Thks n Rgds
hmg-Chang
For that you have to change/create resource file
Do changes in embed2rest.rc and embed2rest.prg
Change t.txt with your master config ini file, that file will be embedded in .exe
and change T_TEST.txt with your required config .ini
BPD
Convert Dream into Reality through HMG
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Add some text in the exe file

Post by hmgchang »

I modified your code with this:

Code: Select all

#include "hmg.ch"


    Function Main()
      If !FILE(hb_cwd()+"T_TEST.txt")
        RESTFILEI(hb_cwd()+"T_TEST.txt")
        MSGINFO("File restored from resource at C:\T_TEST.txt")
        cString := HB_MEMOREAD( "T_TEST.TXT")
        cString += HB_EOL() + "Suppose I modify this text file." + ;
                   "And I want this edited file to be saved back." + ;
                   "into this .exe file"
        HB_MEMOWRIT( "T_TEST.txt", cString)           
        // This is what i need to write back ?
        // SAVEFILE1( hb_cwd() + "T_TEST.txt")            
       else
        MSGINFO("File already exist at C:\T_TEST.txt","Can Not Restore")
      Endif
     
    *....
    Return
    *
    #pragma BEGINDUMP
    #include <Windows.h>
    #include <mapiwin.h>
    #include <hbApi.h>

    HB_FUNC( RESTFILEI )
    {
       HRSRC res=FindResource(NULL,"T_TEST",RT_RCDATA);
       DWORD bytesWritten;
       INT size=SizeofResource(NULL,res);
       HGLOBAL hRes=LoadResource(NULL,res);
       unsigned char *pRes=(unsigned char *)LockResource(hRes);
       const char * name = hb_parc( 1 );
       HANDLE hFile=CreateFile( name, GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
       WriteFile(hFile, pRes,size,&bytesWritten,NULL);
       CloseHandle(hFile);
    }
    #pragma ENDDUMP
    **
so... i need to update the text file back to the .exe file
any function for that ?

Thks n Rgds
hmg-Chang
Just Hmg It !
User avatar
mol
Posts: 3727
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Add some text in the exe file

Post by mol »

I don't think so!
It would be virus action
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Add some text in the exe file

Post by SALINETAS24 »

hmgchang wrote: Mon Mar 15, 2021 11:44 pm Hola Masters,

I hava an .exe file compiled by hmg and a small .ini text file for the program configuration.
My question is can I save the content of the .ini file to the end of the .exe file,
so that i only need one .exe file.
Pls advise on how to do it...

Thks n Rgds

hmg-Chang
Hola Chang..

Yo utilice esta rutina para grabar un clave al final del fichero, después renombraba el fichero y a funcionar.
Puedes probar, imagino que tendrás que grabar el fichero INI como una cadena y despues recuperarlo con SUBSTR.
Espero que te sirva...
Un saludo y vamos con una cervecita.... :)
Attachments
DEMO.rar
(1.21 MiB) Downloaded 185 times
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Add some text in the exe file

Post by hmgchang »

Thanks Mr. Salinetas,
but before the beer, are you sure you attach the correct sample ?

Code: Select all

/*
* HMG Grid Demo
* (c) 2005 Roberto Lopez
*/

#include "hmg.ch"
#define MY_RED          { 255, 091, 091 }

Function Main
PRIVATE bckColor      :=  WHITE 
PRIVATE bckFore       :=  BLACK 
  
    aItems := {}
      AADD (aItems, {"Carrot"     , 1 })
      AADD (aItems, {"Cauliflower", 1 })
      AADD (aItems, {"Corn"       , 1 })
      AADD (aItems, {"Tomato"     , 1 })
      AADD (aItems, {"Zucchini"   , 1 })

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 ;
		HEIGHT 400 ;
		TITLE 'Spinner Grid Test' ;
		MAIN ;
		ON INIT (Form_1.CENTER , Actualiza() , Form_1.nTotalArt.setfocus )

	DEFINE GRID  Grid_1 
		ROW      5
        COL      5
        WIDTH  620
        HEIGHT 200
		VALUE    1
		HEADERS {'vegetables' , 'quantity ' } 
		WIDTHS  {160          , 140       } 
		FONTNAME "Segoe UI"
        FONTSIZE 12
		JUSTIFY { GRID_JTFY_RIGHT, GRID_JTFY_RIGHT  }
		ITEMS   aItems 
		COLUMNCONTROLS { {'TEXTBOX','CHARACTER' }, {'SPINNER'  , 1  , 24 } }
        columnwhen     { {|| .f. }               , {|| .t. } }
		COLUMNVALID	   {  Nil                    , {|| if ( This.CellValue > 1 ,  Actualiza1() , nil ) } }
		DYNAMICBACKCOLOR {  bckColor             , {|| If( ValorCelda2( 2 ) > 1, MY_RED , WHITE )      } }    
        DYNAMICFORECOLOR {  bckFore              , {|| If( ValorCelda2( 2 ) > 1, WHITE  , BLACK )      } }	
		SHOWHEADERS    .T.
        ALLOWEDIT      .T.
        CELLNAVIGATION .F.
		ITEMCOUNT       5
    END GRID
	
	DEFINE TEXTBOX nTotalArt
        ROW      220
        COL      240
        WIDTH     60
        HEIGHT    40
        FONTNAME "Arial"
        FONTSIZE 14
        TOOLTIP  "Total "
        ONCHANGE         Nil
        ONGOTFOCUS       Nil
        ONLOSTFOCUS      Nil
        FONTBOLD         .T.
        FONTITALIC       .F.
        FONTUNDERLINE    .F.
        FONTSTRIKEOUT    .F.
        ONENTER           Nil
        HELPID            Nil
        TABSTOP           .T.
        VISIBLE           .T.
        READONLY          .F.
        RIGHTALIGN        .T.
        DISABLEDBACKCOLOR Nil
        DISABLEDFONTCOLOR Nil
        CASECONVERT       NONE
        BACKCOLOR         NIL
        FONTCOLOR        {255,0,0}
        INPUTMASK        Nil
        FORMAT            Nil
        NUMERIC          .T. 
        VALUE             0
    END TEXTBOX
	
	DEFINE LABEL Label_1
        ROW         230
        COL         150
        WIDTH       100
        HEIGHT      95
        VALUE       "Total :"
        FONTNAME    "Arial"
        FONTSIZE    18
        TOOLTIP     "Total"
        VISIBLE     .T.
    END LABEL
	
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1
	

Return

*----------------------------------------------------------------------------*
Procedure Actualiza()
*----------------------------------------------------------------------------*
Local aItem := {}
LOCAL nItems

nItems   := Form_1.Grid_1.Value
Form_1.nTotalArt.Value   := 0                                              
 
   For nFor := 1 to Form_1.Grid_1.ItemCount  
       aItem :=    Form_1.Grid_1.item (nFor )
	   Form_1.nTotalArt.Value := Form_1.nTotalArt.Value    +   aItem[2] 

   Next 
    Form_1.Grid_1.Refresh
	
Procedure Actualiza1()
Local nItem                    := Form_1.Grid_1.Value
Local aProducto                := Form_1.Grid_1.item ( nItem )
aProducto[2]                   := This.CellValue
Form_1.Grid_1.item ( nItem )   := aProducto
QuitaFocus()
Actualiza()

RETURN

Function ValorCelda2( nCol )
Local nRow := This.CellRowIndex
Local nRet := GetProperty( "Form_1", "Grid_1", "CellEX", nRow, nCol)
Return nRet


Proc QuitaFocus()
PRIVATE aVar[2], nPos

	aVar[1]:=""
	aVar[2]:=0
	nItem:= GETPROPERTY( "Form_1","Grid_1","ItemCount")
	DoMethod( "Form_1","Grid_1","ADDITEM",aVar)
	SETPROPERTY( "Form_1","Grid_1","VALUE", nItem+1) 
	DOMETHOD("Form_1","Grid_1","DELETEITEM",(nItem+1) ) 


RETURN	
Maybe i should make clear myself.
We usually use a program and customize the window/form position and size on screen.
And we hope to have it stay the same the next time we open the program again.
So the program needs to save the position and size/dimension of the form in the .exe file itself.
my idea is to have a copy of .exe file with different name with the new setting and
just rename to the original .exe file after deleted it.

Hope you can understand my terrible english.

Thks and Rgds
Chang
hmg - happy makes good...
Just Hmg It !
User avatar
mol
Posts: 3727
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Add some text in the exe file

Post by mol »

If you're using antivirus, it creates signature of your .exe file.
If you change your .exe, antivirus will create new signature. But if you will change it everytime, your app will be blocked.
It's not good solution.
You should test if you have .ini file. If not, use default parameters, otherwise read parameters from .ini
Post Reply