Manual for .RES file format

New to FreeBASIC? Post your questions here.
JaDogg
Posts: 345
Joined: Apr 13, 2008 12:11
Location: Sri Lanka - Negombo
Contact:

Manual for .RES file format

Postby JaDogg » Aug 07, 2008 4:26

does any one knows a nice looking downloadable manual for .RES file manupilation, Or a Res compiler written in basic language(SRC code)
[Not msdn topics they are incorrect(the topic Resource File Format)]
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Aug 07, 2008 5:24

Heres some simple info... maybe its helpful?? at lest not from microsoft directly - but I don't know if thats where it originated or not.


http://www.wotsit.org/list.asp?search=.res&button=GO!

another

http://www.softhelp.ru/fileformat/res32/res32fmt.htm
Sisophon2001
Posts: 1704
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Postby Sisophon2001 » Aug 10, 2008 7:14

This page has the gorc manual.

http://www.jorgon.freeserve.co.uk/

Garvan
JaDogg
Posts: 345
Joined: Apr 13, 2008 12:11
Location: Sri Lanka - Negombo
Contact:

Postby JaDogg » Aug 12, 2008 3:41

ok
please help me to make this code work
it should add resourcses from a res to an exe

Code: Select all

'not working please help
'
#include "windows.bi"
#include "win/shellapi.bi"
#define WIN_INCLUDE_ALL

#define CWZS(a) cast( LPCWSTR , a )

type reshead1
   datasize as dword ' this is what we need
   headersize as dword
end type
type reshead2
   dataversion as dword
   memoryflags as word
   languageid as word 'needed
   version as dword
   characteristics as dword
end type

dim shared exefile as string
dim shared resfile as string
dim shared iexefile as integer
dim shared iresfile as integer
dim shared zresdata as string
dim shared endpos as integer
dim shared curpos as integer ptr
dim shared err_msg as string
dim shared argc as integer
dim shared i as integer
dim shared domutation as integer
dim shared hkernel32 as HINSTANCE
dim shared hunicows as HINSTANCE
'
'Functions loaded at runtime
'

dim shared xbeginupdateresource as function( byval pFileName as LPCWSTR, _
byval bDeleteExistingResource as BOOL ) as HANDLE

dim shared xupdateresource as function( byval hUpdate as HANDLE, _
byval lpType as LPCWSTR, byval lpName as LPCWSTR, _
byval wLanguage as word, byval lpData as PVOID, byval cbData as dword ) as BOOL

dim shared xendupdateresource as function( byval hUpdate as HANDLE, _
byval fDiscard as BOOL ) as BOOL


'sub exitapp(  )
'   DyLibFree (hkernel32) :  DyLibFree (hunicows)
'end sub
sub commandlinechk(  )
   do
      argc+=1
      if command (  argc  ) = "" then
         exit do
      endif

   loop

   if argc <> 3 then ? "Invalid Commands" : end

end sub
sub checkexe(  )
   dim ixtype as integer
   ixtype = shgetfileinfo(  strptr( exefile ) , 0 , 0 , 0 , SHGFI_EXETYPE  )

   if ixtype = 0 then goto invalidx

   if mkshort( loword( ixtype ) ) = "PE" then
      if not hiword( ixtype ) = 0 or hiword( ixtype ) = 35 or hiword( ixtype ) = 40 then
         goto invalidx
      endif
   endif

   exit sub
   invalidx:
   ? "Invalid exe file" : end
end sub
sub loadfunctions(  )

   hkernel32 =  dylibload(  "Kernel32.dll" )
   hunicows  =  dylibload(  "Unicows.dll"  )

   xbeginupdateresource = dylibsymbol( hkernel32 , "BeginUpdateResourceW"  )

   if xbeginupdateresource     = 0 then
      xbeginupdateresource     = dylibsymbol( hunicows , "BeginUpdateResourceW"  )
      if xbeginupdateresource  = 0 then
         dylibfree(hkernel32) :  dylibfree (hunicows) : ? "Unable to load functions" : end
      else
         xupdateresource       = dylibsymbol( hunicows , "UpdateResourceW" )
         xendupdateresource    = dylibsymbol( hunicows , "EndUpdateResourceW" )
         if xupdateresource = 0 or xendupdateresource = 0 then
            dylibfree (hkernel32) :  dylibfree (hunicows) : ? "Unable to load functions" : end
         endif
      endif
   else
      xupdateresource       = dylibsymbol( hkernel32 , "UpdateResourceW" )
      xendupdateresource    = dylibsymbol( hkernel32 , "EndUpdateResourceW" )
      if xupdateresource = 0 or xendupdateresource = 0 then
         dylibfree (hkernel32) :  dylibfree (hunicows) : ? "Unable to load functions" : end
      endif
   endif
end sub
function csunicode( sdata as string ) as string
   dim ilen as integer, wstemp as string
   ilen = len( sdata ) + 1
   wstemp = string( ( ilen * 2 ), 0 )
   multibytetowidechar ( getacp, 0, strptr( sdata ), ilen, cast( LPCWSTR, strptr( wstemp ) ), ilen )
   return wstemp
end function
function getuzstring( ifile as integer )as string
   dim bdata as ubyte,bdata2 as ubyte
   dim zstr as string

   do
      get #ifile, , bdata
      get #ifile, , bdata2
      if bdata = 0 and bdata2 = 0 then exit do
      zstr += chr( bdata ) + chr( bdata2 )
   loop

   return zstr
end function
sub loadresfile(  )
   dim zt as zstring ptr
   dim szutmp as string
   dim hupd as HANDLE
   dim xreshead1 as reshead1
   dim xreshead2 as reshead2
   dim wrtmp as word
   dim iresfile as integer
   dim typeord as word
   dim typenam as string
   dim nameord as word
   dim namenam as string 
   dim bisnnam as boolean
   dim bistnam as boolean
   dim resdata as string
   dim xu as string
   dim as any ptr apname,aptype
   
   iresfile = freefile
   '   ? iresfile
   '   ? resfile
   open resfile for binary access read as #iresfile
   if err <> 0 then ? "Unable opening resfile : " + resfile : end
   if not lof( iresfile ) > 35 then ? "Resource file too small : " + resfile : end
   zresdata = space( 32 )
   get #iresfile, , zresdata
   if zresdata = string( 4, 0 ) + chr( 32, 0, 0, 0, 255, 255, 0, 0, 255, 255 ) + string( 18, 0 ) then

      szutmp = csunicode( exefile )
      hupd = xbeginupdateresource( CWZS( @szutmp ) , 0 )
      if hupd = 0 then
         ? "Unable to call BeginUpdateResourceW , if your os is not NT you need 'Unicows.dll'" :  end
      endif
      do
      get #iresfile , , xreshead1
      get #iresfile , , wrtmp
      if wrtmp = &hffff then
         'it is a ordinal
         get #iresfile , , typeord
         bistnam = false
         apname = @typeord
      else
         'it is a name
          typenam = mkshort( wrtmp ) + getuzstring( iresfile )
          bistnam = true
          apname = @typenam
      endif
      get #iresfile , , wrtmp
      if wrtmp = &hffff then
         'name  is a ordinal
         get #iresfile , , typeord
         bistnam = false
         aptype = @typeord
      else
         'name it is a name : how crazy this is
          namenam = mkshort( wrtmp ) + getuzstring( iresfile )
          bisnnam = true
          aptype = @namenam
      endif
      get #iresfile , , xreshead2
      resdata = space( xreshead1.datasize )
      get #iresfile , , resdata
      xu = csunicode(resdata)
     xupdateresource(hupd , (aptype) , (apname) , xreshead2.languageid , CWZS(@xu) , xreshead1.datasize )
      loop until eof( iresfile )
   else
      ' invalid res file
      close #iresfile
      ? "Invalid resource file" : end
   endif
   xendupdateresource(hupd,0)
   close #iresfile
end sub
'sub addresdata(  )
'   do
'
'   loop
'end sub
sub changeexe(  )
   dim iexefile as integer
   iexefile = freefile
   open exefile for binary access write as #iexefile
   put #iexefile,,"MZ\r\nJaDogg\r\n" ' ok my name as the begining
   close #iexefile
end sub
'______________________________________________________________________________________________________________________

'---
'Get Some Information
'
'
? "JaDogg Exe Link3r v0.0.0.1"
? "Copyright (c) 2008 JaDogg(aka Bhathiya Perera)"
?
'commandlinechk(  )
exefile = "sds.exe"
resfile = "setup.res"
loadfunctions(  )
checkexe(  )
loadresfile(  )

'addresdata(  )
changeexe(  )
'resfile = command( 1 )
'loadresfile
'if ( argc > 3 ) or ( argc < 2 ) then
'   Err_Msg = "Too Few Commands"
'   goto ErrMsg
'endif
'for i = 1 to argc
'   if (  ( ucase( left( command(  i  ), 2 ) ) ) = "-M"  ) then
'      domutation = true
'      Mutation = right( command(  i  ), len( command(  i  ) )-2 )
'   elseif (  ( ucase( left( command(  i  ), 2 ) ) ) = "-O"  ) then
'      ResObjfile = right( command(  i  ), len( command(  i  ) )-2 )
'   elseif (  ( ucase( left( command(  i  ), 2 ) ) ) = "-X"  ) then
'      Exefile = right( command(  i  ), len( command(  i  ) )-2 )
'   endif
'next
'

'----------
sleep
end
counting_pine
Site Admin
Posts: 6200
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Aug 12, 2008 16:10

Perhaps I shouldn't be intruding into this thread, since I don't know much about using resources, but #define WIN_INCLUDE_ALL won't do anything if you use it after #include "windows.bi". It only takes effect if it's defined before processing the header.

It might also be helpful if you can be more specific on how/where it's failing.
Does it compile OK? If not, it might be because of the misplaced WIN_INCLUDE_ALL.
JaDogg
Posts: 345
Joined: Apr 13, 2008 12:11
Location: Sri Lanka - Negombo
Contact:

Postby JaDogg » Aug 13, 2008 9:54

counting_pine wrote:Perhaps I shouldn't be intruding into this thread, since I don't know much about using resources, but #define WIN_INCLUDE_ALL won't do anything if you use it after #include "windows.bi". It only takes effect if it's defined before processing the header.

It might also be helpful if you can be more specific on how/where it's failing.
Does it compile OK? If not, it might be because of the misplaced WIN_INCLUDE_ALL.


hey,the problem is i dont know how it fails
Sisophon2001
Posts: 1704
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Postby Sisophon2001 » Aug 13, 2008 14:43

Your code is very complex (for anybody), so forgive me if I ask what are you doing.

If you want to access resources from a resource file, I have seen many examples of that, so I could look them up and share them.

If you want to append a binary file to the end of an exe, and then read it, then there is an example of that on my website. And I think 1000101 posted a library to make this easier (I have not had the need to test it yet).

If you need to convert ascii to unicode, I would need to do a bit of research, because I never did it with FB, but I don't think your code will work from a quick review.

If you want to read a compiler resource file, I have no idea how to do it, but my first step would be to look at the source code of FbEdit which reads resource files the last time I looked.

There seams to be nothing to test in he code you posted. What should happen that is not working?

Garvan
counting_pine
Site Admin
Posts: 6200
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Aug 13, 2008 23:18

JaDogg wrote:the problem is i dont know how it fails
It would help readers though, if you can post, if not how it fails, but *in what way* it fails. For example, does it compile?
If it doesn't, then there's an error in the actual code that needs fixing before it will compile. Here, it will usually be helpful to report the error message the compiler gives you.
If it compiles, then the problem is in how the program runs.
If you have problems when running a program it can be difficult to be more specific, but it can fail in several ways:
- There's no response when you try to run it
- The program runs, but gets stuck and doesn't seem to do anything
- The program just shows a blank screen
- The program crashes
- The program works mostly OK, but behaves weirdly in some cases
- and so on...

If you can be as specific as you can when describing a problem, then it will save people from having to download, compile, run and test your code, working on faith that at some point they'll probably run into an error of some sort.

In some cases, just knowing the error might enable people to point you to a solution.

So in general, when saying that a program doesn't work, it helps both you and others if you go into more detail.
JaDogg
Posts: 345
Joined: Apr 13, 2008 12:11
Location: Sri Lanka - Negombo
Contact:

Postby JaDogg » Aug 22, 2008 3:39

i know it is a bit complex but only thing i want to do is update resources of an exe using a win32 res file

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest