News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

MAKEINTRESOURCE - finding and loading resource strings

Started by IanScott, September 17, 2014, 08:31:30 AM

Previous topic - Next topic

IanScott

I am trying to load a string resource using firstly FindResource and then LoadResource. This is the function I have defined to do it.

getRsrcString proc resStringID:DWORD, hMod:DWORD

   ; Find the resource string
   invoke FindResource, hMod, resStringID, RT_STRING
      
   ; Get the resource string
   invoke LoadResource, hMod, eax                        
   ret
               
getRsrcString endp

The resStringID argument is defined in an equates. eg  fileMaskEmpty  equ 2000
This and other resource string equates refer to the following section of a resource file

// String resources
#define fileMaskEmpty                2000
#define fileMask1                       2002
#define fileMask2                       2003
#define fileMask3                       2004
#define fileMask4                       2005
#define fileMask5                       2006

STRINGTABLE
BEGIN
    fileMaskEmpty           " "
    fileMask1               "*.html"
    fileMask2               "*.sql"
    fileMask3               "*.txt"
    fileMask4               "*.sql;*.txt"
    fileMask5               "*.xml"
END

The call to FindResource is failing. I suspect this is because I am passing an integer in the lpName argument and not a LPCTSTR. The MSDN documentation recommends the MAKEINTRESOURCE macro as a way of translating from an integer value to a LPCTSTR value. However I have read a post by dedndave from July 03, 2014 in which he states...

" well, in the world of ASM, we don't really need to use a MAKEINTRESOURCE macro
what that text is really saying is
1) of lpMenuName is less than 65536, it's an integer identifier (600, in your case)
2) otherwise, it's the address of a null-terminated string (menu name) "

And this works a treat when I load an icon from a resource file by passing the resource identifier as an integer. Not so great when I try to load a string although in both cases their resource identifiers are less than 65536.

Thanks




sinsi

Have you tried using LoadString?

Quote from: MSDN FindResource
An application can use FindResource to find any type of resource, but this function should be used only if the application must access the binary resource data by making subsequent calls to LoadResource and then to LockResource.

To use a resource immediately, an application should use one of the following resource-specific functions to find the resource and convert the data into a more usable form.
🍺🍺🍺

dedndave

LoadString will probably work for you, as Sinsi suggested

if you want a more "universal" routine that may be used for loading any type resource...

http://masm32.com/board/index.php?topic=967.0

if you follow that thread, there are also routines for working with group resources

jj2007

LoadString is easy to use (and works under the hood of Res$()), BUT for your particular application, i.e. OPENFILENAME filters, beware of a nasty bug in the Unicode version of LoadString.


Vortex

Hi IanScott,

Here is an example for you :

include     \masm32\include\masm32rt.inc

BUFF_SIZE   equ 32

IDS_STRING2 equ 2

.data?

buffer      db BUFF_SIZE dup(?)

.code

start:

    invoke  GetModuleHandle,0

    invoke  LoadString,eax,IDS_STRING2,\
            ADDR buffer,BUFF_SIZE

    invoke  StdOut,ADDR buffer

    invoke  ExitProcess,0

END start