flat assembler
Message board for the users of flat assembler.

Index > Windows > text resources

Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
How would you declare a text resource in the resource section?
Post 26 May 2006, 18:48
View user's profile Send private message Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum
A string table?
Post 27 May 2006, 00:35
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
Code:
STRINGTABLE
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
{
102,    "testtt"
}
    


LoadString(hInstance,102,szBuffer,20);
Post 27 May 2006, 08:17
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Vasilev: I mean using fasm macros
Post 27 May 2006, 10:47
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Hey Thomasz! can you help me out with this one? You know your macros better than anyone, especially me. Very Happy
Post 29 May 2006, 23:19
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Code:
  include '%fasminc%\encoding\win1250.inc' ; choose encoding

  directory RT_STRING, dir_strings

; STRINGTABLE's id = 1
  resource  dir_strings,\
            1, LANG_ENGLISH+SUBLANG_DEFAULT, res_strings

; STRINGTABLE can have STRINGS with ids between 1-16
  resdata         res_strings
   du 0          ; id = 1
   du 0          ; id = 2
   du 'aaa',0    ; this STRING's id = 3
  endres    
How it works? Whole STRINGTABLE has id 1 (check resource macro above). So the stringtable contains all strings with id between (1-16). If it's id was 2 the stringtable would contain strings with ids (17-32), etc. You pass string's id to LoadString API (so 3 in this case). I hope you get the idea, because I realise I didn't explain it clearly Smile
Post 30 May 2006, 16:09
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Thanks Reverend,
But I couldn't get it to work properly, so I just decided to use the visual C++ compiler to compile the resource. And now it works. I tried to find the data format using google but all information I found uses the HLL resource macros. Does anyone know where to find the raw resource data formats?
Post 31 May 2006, 10:55
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Now I know 100% right (last time I didn't check it, just sent message Smile). Here is the working example:
Code:
  include '%fasminc%\encoding\win1250.inc' ; choose encoding 

  directory RT_STRING, dir_strings 
  resource  dir_strings,\ 
            1, LANG_ENGLISH+SUBLANG_DEFAULT, res_strings 

; STRINGTABLE with id = 1 can have STRINGS with ids between 0-15
  resdata         res_strings 
   du 0          ; id = 0
   du 0          ; id = 1 
   du 5, 'aaaaa' ; id = 2
   du 4, 'test'  ; id = 3
  endres    
Post 31 May 2006, 19:05
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Hate to say it Reverend, but still crashing on me. did everything you showed me in your code post. I'll have to see if I can find the raw data format somehow. I haven't any luck googling so far. If anyone else has had success with this please let me know.
MadMatt
Post 02 Jun 2006, 08:57
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Here is the whole working code. At least it works correct for me. Let me know what doesn't work for you if it stills occurs.
Code:
        format  PE GUI 4.0

        include '%fasminc%\win32a.inc'

        include '%fasminc%\encoding\win1250.inc'

section '.text' code readable writeable executable

        invoke  LoadString, 0, 2, buffer, buffer.size
        invoke  MessageBox, 0, buffer, buffer, MB_OK
        invoke  LoadString, 0, 3, buffer, buffer.size
        invoke  MessageBox, 0, buffer, buffer, MB_OK
        ret

section '.data' data readable writeable

  buffer        rb 256
  buffer.size   =  256

section '.idata' readable writeable

  data import

   library user32,'USER32.DLL'

   import user32,\
          LoadString,'LoadStringA',\
          MessageBox,'MessageBoxA'

  end data

section '.rsrc' data readable writeable resource

  directory RT_STRING, dir_strings

  resource  dir_strings,\  
            1, LANG_ENGLISH+SUBLANG_DEFAULT, res_strings  

  resdata         res_strings
   du 0          ; id = 0 
   du 0          ; id = 1  
   du 5, 'aaaaa' ; id = 2 
   du 4, 'test'  ; id = 3 
  endres    
Post 04 Jun 2006, 19:32
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Anyone knows how to do string resources multi-language?

Code:
section '.rsrc' data readable writeable resource 

  directory RT_STRING, dir_strings, RT_STRING, dir_strings_sp

  resource  dir_strings,\   
            1, LANG_ENGLISH+SUBLANG_DEFAULT, res_strings   
  resdata         res_strings
   du 0          ; id = 0  
   du 0          ; id = 1   
   du 5, 'aaaaa' ; id = 2  
   du 4, 'test'  ; id = 3  
  endres

  resource  dir_strings_sp,\
            1, LANG_SPANISH, res_strings_sp
  resdata         res_strings_sp
   du 0          ; id = 0  
   du 0          ; id = 1   
   du 5, 'aaaaa' ; id = 2  
   du 4, 'prueba'  ; id = 3
  endres
    


The resource section above compiles but in my spanish instalation of Windows XP always shows 'test' instead of 'prueba'.

Reverend, note that if you change 'test' with 'test1234' your program displays 'test' anyway.
Post 04 Jun 2006, 21:53
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM
The prefixing byte is the length. (I had this error too.)
So, you would change 4,'test' to 8,'test1234' and not 4,'test1234'
Post 04 Jun 2006, 22:19
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
ahahaha, I thought that the prefixing byte was the ID (yes, I know that the coments doesn't say the same)

Thanks!!
Post 04 Jun 2006, 22:43
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Hey reverend, thanks for your help! Very Happy Finally got my program working! Cool I realize what I was doing wrong Embarassed , and thanks to locodelassembly's question and UCM's revelation Smile (that's not the ID its the LENGTH!), I was able to find the error and correct it (along with a few other bugs).
Post 05 Jun 2006, 08:17
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Huh, I forgot to mention it's not the ID preceding the text Smile but it's the string's length Smile

locodelassembly: I have just written a simple wrapeer for your needs. Here it is:
Code:
proc    LoadStringEx    hInstance, uID, lpBuffer, nBufferMax, wLang:WORD
        mov     eax, [uID]
        shr     eax, 4
        inc     eax
        movzx   edx, [wLang]
        invoke  FindResourceEx, [hInstance], RT_STRING, eax, edx
        invoke  LoadResource, [hInstance], eax
        mov     ecx, [uID]
        and     ecx, 0FFFFFFF0h
        sub     ecx, [uID]
        neg     ecx
      @@:
        movzx   edx, word [eax]
        lea     eax, [eax+edx*2+2]
        loop    @B
        movzx   ecx, word [eax]
        lea     edx, [eax+2]
        invoke  WideCharToMultiByte, 0, 0, edx, ecx, [lpBuffer], [nBufferMax], 0, 0
        ret
endp    

And here is the whole code using it (NOTE that both stringtables have the same id but different language):
Code:
        format  PE GUI 4.0

        include '%fasminc%\win32a.inc'

        include '%fasminc%\encoding\win1250.inc'

section '.text' code readable writeable executable

        stdcall LoadStringEx, 0, 2, buffer, buffer.size, LANG_ENGLISH+SUBLANG_DEFAULT
        invoke  MessageBox, 0, buffer, buffer, MB_OK
        stdcall LoadStringEx, 0, 2, buffer, buffer.size, LANG_POLISH+SUBLANG_DEFAULT
        invoke  MessageBox, 0, buffer, buffer, MB_OK
        ret

proc    LoadStringEx    hInstance, uID, lpBuffer, nBufferMax, wLang:WORD
        mov     eax, [uID]
        shr     eax, 4
        inc     eax
        movzx   edx, [wLang]
        invoke  FindResourceEx, [hInstance], RT_STRING, eax, edx
        invoke  LoadResource, [hInstance], eax
        mov     ecx, [uID]
        and     ecx, 0FFFFFFF0h
        sub     ecx, [uID]
        neg     ecx
      @@:
        movzx   edx, word [eax]
        lea     eax, [eax+edx*2+2]
        loop    @B
        movzx   ecx, word [eax]
        lea     edx, [eax+2]
        invoke  WideCharToMultiByte, 0, 0, edx, ecx, [lpBuffer], [nBufferMax], 0, 0
        ret
endp

section '.data' data readable writeable

  buffer        rb 256
  buffer.size   =  256

section '.idata' readable writeable

  data import

   library user32,'USER32.DLL',\
           kernel32,'KERNEL32.DLL'

   import user32,\
          LoadString,'LoadStringA',\
          MessageBox,'MessageBoxA'

   import kernel32,\
          FindResourceEx,'FindResourceExA',\
          LoadResource,'LoadResource',\
          WideCharToMultiByte,'WideCharToMultiByte'

  end data

section '.rsrc' data readable writeable resource

  directory RT_STRING, dir_strings

  resource  dir_strings,\  
            1, LANG_ENGLISH+SUBLANG_DEFAULT, res_strings_eng,\
            1, LANG_POLISH+SUBLANG_DEFAULT,  res_strings_pl

  resdata         res_strings_eng
   du 0           ; id = 0
   du 0           ; id = 1
   du 6, 'length' ; id = 2
  endres

  resdata         res_strings_pl
   du 0           ; id = 0
   du 0           ; id = 1
   du 7, 'dlugosc'; id = 2
  endres    

EDIT: It works for these two examples for sure. I didn't test it further, it's possible that the proc may need some changes to be more universal
Post 05 Jun 2006, 17:56
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Hey thanks Reverend!!

I found an easiest way making a little change to your resource section
Code:
section '.rsrc' data readable writeable resource 

  directory RT_STRING, dir_strings 

  resource  dir_strings,\   
            1, LANG_ENGLISH+SUBLANG_DEFAULT, res_strings_eng,\ 
            1, LANG_SPANISH, res_strings_sp

  resdata         res_strings_eng 
   du 0           ; id = 0 
   du 0           ; id = 1 
   du 6, 'length' ; id = 2
   du 8, 'a string'
  endres 

  resdata         res_strings_sp
   du 0           ; id = 0 
   du 0           ; id = 1 
   du 6, 'tamaño'; id = 2
   du 10, 'una cadena'
  endres    


Using that resource section (and changing encoding to WIN1252) with your first working program displays "tamaño"(this one required the new encoding for the "ñ" character) and "una cadena" on my system. If I replace LANG_SPANISH with LANG_POLISH then "length" and "a string" are displayed.

Thanks again!!
Post 05 Jun 2006, 19:00
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
I think it depends on what language is set in your operating system. I guess you have Spanish set. And so somewhere deep in kernel32.dll code (exactly somewhere in innards of FindResource) it searches first for Spanish resource. But my proc is supposed to work on every language. And so you can have English, Polish, Spanish, Chinese or every other encoding Smile and just pass it to my proc.
Post 05 Jun 2006, 21:03
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
That's true but what I was finding is a way in which the applicacion shows the apropiate strings based on the language of the installed OS. In your case I can select the language and in my case Windows selects it for me (and if the native language is not present then the SUBLANG_DEFAULT is used).
Post 05 Jun 2006, 22:48
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
I'm a necromancer! )) Ressurecting an old topic.

Tried to figure out how to compile string resorces, and I'm afraid there's something wrong with resources.inc

I'm using [url='http://melander.dk/reseditor/']Resource Editor[/url] to check compiled resources

At first I tried to add string resources mannually using the macros:
Code:
section '.rsrc' data readable resource
include 'include/macros/resource.inc'
include 'include/macros/utf-8.inc'

  directory 6, res_strings
  resource res_strings,\
    1, 0, res_strings_eng
  
  resdata res_strings_eng
    du 7, '!?@02:0'
    du 7,'*9DJE'*'
  endres
    

It compiles OK, but when I open the binary in the resource editor, I get an error: String table (#1): Premature end of data
And String Table is shown as on screenshots below:
Image
Image
But then I tried to include precompiled .res file, created with RC.EXE ver 6.2
Code:
section '.rsrc' data readable resource from 'sz.res'    

and sz.rc:
Code:
STRINGTABLE
BEGIN
0 L"\x0421\x043f\x0440\x0430\x0432\x043a\x0430"
1 L"\x062a\x0639\x0644\x064a\x0645\x0627\x062a"
END    

Resource editor didn't show any errors and resources were good:
Image
Is there a bug in a macro which causes incorrect resources? However, .exe files produced with resources from macros work and display information OK, as you all know. It's veeery strange
Post 06 May 2014, 22:49
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.