The MASM Forum

General => The Campus => Topic started by: xandaz on November 12, 2019, 05:08:52 AM

Title: Problems with resource.
Post by: xandaz on November 12, 2019, 05:08:52 AM
    Hi Guys. I'm trying to get back on track. I've been useing resource hacker to make the .rc file. When i assemble it all the resources don't get inside the .EXE file. Why is that. I seem to remember an old fashioned way where every resource had it's own ID but resource hacker doesnt work like that.
    can somone help?
    Thanks in advance
Title: Re: Problems with resource.
Post by: hutch-- on November 12, 2019, 06:19:49 AM
Its a good tool but probably not the right one for your task. Why not write an RC script ?
Title: Re: Problems with resource.
Post by: TimoVJL on November 12, 2019, 07:27:00 AM
http://www.resedit.net
Title: Re: Problems with resource.
Post by: xandaz on November 12, 2019, 08:01:38 AM
   Thanks Hutch. Could you kindly direct me to information needed to write RC scripts? while i search for myuself as well of course.
   One Thanks not enough.
   be seein you
Title: Re: Problems with resource.
Post by: hutch-- on November 12, 2019, 10:50:29 AM
http://masm32.com/board/index.php?topic=6512.0
Title: Re: Problems with resource.
Post by: xandaz on November 12, 2019, 08:25:59 PM
   that's exactlly what i was looking for. Thanks
Title: Re: Problems with resource.
Post by: xandaz on November 12, 2019, 08:49:44 PM
    Look...i know you've helped me a lot but i still have questions. i made the rc file. No resources are found inside the  exe file. why is that?
What am i not doing?
    Thanks again in advance
Title: Re: Problems with resource.
Post by: jj2007 on November 12, 2019, 09:54:29 PM
Does the commandline care for the rc and res files? I don't know what IDE or editor you are using...
Title: Re: Problems with resource.
Post by: xandaz on November 12, 2019, 10:48:43 PM
    I'm using ResEd JJ and QEditor for the assedmbly. Isn't that enough? I've been looking into ml and link command line options but see nothing regarding the rc files...
    thanks
Title: Re: Problems with resource.
Post by: xandaz on November 12, 2019, 10:58:16 PM
    So.... i found out i need to use the resource compiler but still no resources found in .exe file when i imagelist_loadimage them.
Title: Re: Problems with resource.
Post by: jj2007 on November 12, 2019, 11:52:51 PM
I don't use qEditor regularly, but as far as I remember, the build process includes resources if it finds a rsrc.rc in the path of the source. See in particular \Masm32\menus.ini and \Masm32\bin\bldallc.bat

How did you name your resource file?
Title: Re: Problems with resource.
Post by: hutch-- on November 13, 2019, 12:07:49 AM
Just have a look in the examples, \masm32\examples\dialogs_later\

The default way of using dialogs is to name the RC file rsrc.rc
Title: Re: Problems with resource.
Post by: hutch-- on November 14, 2019, 01:33:06 PM
Here is a very simple example, mainly so you can see the basic techniques for constructing a resource dialog. The RC file can be edited with Ketil Olsen's Resed.
Title: Re: Problems with resource.
Post by: Vortex on November 16, 2019, 04:52:45 AM
Hi xandaz,

Resource Hacker provides an option to save resources as compiled scripts, .res files.
Title: Re: Problems with resource.
Post by: xandaz on November 20, 2019, 06:51:24 AM
    Well  guys... things have adavanced a little and i provided a non-working example for you to see what the heck is wrong, if you please.
    The LoadBitmap function returns resource name not found. Also tried the identifier. doesn't work either.
    thanks in advance
Title: Re: Problems with resource.
Post by: Vortex on November 20, 2019, 07:05:46 AM
Hi xandaz,

You should respond the WM_PAINT message to display the bitmap with BitBlt :

Tutorial 25: Simple Bitmap

http://www.interq.or.jp/chubu/r6/masm32/tute/tute025.html

.elseif uMsg==WM_PAINT
      invoke BeginPaint,hWnd,addr ps
      mov    hdc,eax
      invoke CreateCompatibleDC,hdc
      mov    hMemDC,eax
      invoke SelectObject,hMemDC,hBitmap
      invoke GetClientRect,hWnd,addr rect
      invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
      invoke DeleteDC,hMemDC
      invoke EndPaint,hWnd,addr ps
Title: Re: Problems with resource.
Post by: xandaz on November 20, 2019, 07:09:31 AM
    I still remember that part. the thing is that the LoadBitmap function resturns ERRROR_RESOURCE_NAME_NOT_FOUND.
    thanks vortex
Title: Re: Problems with resource.
Post by: jj2007 on November 20, 2019, 09:19:03 AM
Hi Xandaz,

Some error checks help to find the culprits:
        invoke  LoadImage,hInstance,addr MainWindowIcon,IMAGE_ICON,32,32,LR_LOADFROMFILE
        deb 4, "LoadImg", eax, $Err$()
...
            invoke  LoadBitmap,hInstance, addr Bmp
            deb 4, "LoadBmp", eax, $Err$()

LoadImg
eax             0
$Err$()         Access denied.

LoadBmp
eax             0
$Err$()         Impossible finding the name of resource.


With a few changes:
        invoke  LoadImageW,hInstance,addr MainWindowIcon,IMAGE_ICON,32,32,LR_LOADFROMFILE
        deb 4, "LoadImg", eax, $Err$()
...
            invoke  LoadBitmap,hInstance, 100
            deb 4, "LoadBmp", eax, $Err$()

LoadImg
eax             248644207
$Err$()         Operation completed.

LoadBmp
eax             285541561
$Err$()         Operation completed.


I have added Vortex' code, too. Now it shows a little red circle in the upper left corner.

Note that resources can have names like "bmp". But in general, integers are easier to handle - and you did use an integer in the rc file: #define bmp 100
Title: Re: Problems with resource.
Post by: xandaz on November 20, 2019, 09:25:15 PM
    Thanks JJ. You solved the problem.
    Thanks you guys. You're the best.
Title: Re: Problems with resource.
Post by: xandaz on November 23, 2019, 07:22:02 AM
    Well guys a new problem takes place when you use LoadImage instead of loadBitmap. I've tried both the resource name and identifier and it doesn't work. The thing is i wanted to use ImageList_LoadImage to load the images for a toolbar. Any ideas?
   Thanks in advance.
Title: Re: Problems with resource.
Post by: Vortex on November 23, 2019, 07:53:48 AM
Hi xandaz,

You can load a bitmap without creating a resource file :

   .IF uMsg==WM_CREATE
   
        invoke  LoadImage,0,ADDR filename,\
                IMAGE_BITMAP,0,0,LR_LOADFROMFILE
        mov     hBitmap,eax   

        invoke  GetObject,eax,SIZEOF(BITMAP),ADDR bm
       
   .ELSEIF uMsg==WM_PAINT
   
        invoke  BeginPaint,hWnd,ADDR ps
        mov     hdc,eax
        invoke  CreateCompatibleDC,eax
        mov     hMemDC,eax
       
        invoke  SelectObject,eax,hBitmap

        mov     edx,OFFSET bm
           
        xor     eax,eax
        invoke  BitBlt,hdc,eax,eax,\
                BITMAP.bmWidth[edx],\
                BITMAP.bmHeight[edx],\
                hMemDC,eax,eax,SRCCOPY

        invoke  DeleteDC,hMemDC
        invoke  EndPaint,hWnd,ADDR ps
Title: Re: Problems with resource.
Post by: Vortex on November 23, 2019, 08:06:36 AM
Hi xandaz,

Loading a bitmap from a resource, the .rc script :

100 BITMAP logo.bmp

   .IF uMsg==WM_CREATE
   
        invoke  LoadImage,hInstance,100,\
                IMAGE_BITMAP,0,0,0
        mov     hBitmap,eax
Title: Re: Problems with resource.
Post by: xandaz on November 23, 2019, 09:15:54 AM
    Vortex....tried the same but still not working. take a look if you will....
    thanks.
Title: Re: Problems with resource.
Post by: fearless on November 23, 2019, 10:02:01 AM
You have this:
invoke  LoadImage,hInstance,addr Bmp,IMAGE_BITMAP,64,64,0

Which refers to this:
UCSTR              Bmp,"bmp",0

try:
.const
BMP_MYBITMAP EQU 100 ; same ID as defined in the resource


invoke LoadImage, hInstance, BMP_MYBITMAP, IMAGE_BITMAP, 64, 64, 0
Title: Re: Problems with resource.
Post by: xandaz on November 23, 2019, 08:23:56 PM
    Hey guys ... it still dont work. what am i forgetting to do? there's always something....
    ty guys
Title: Re: Problems with resource.
Post by: Vortex on November 23, 2019, 08:44:26 PM
Hi xandaz,

The bitmap handle should not be a local variable :

WndProc     PROC    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

         ; local    hBitmap:DWORD


.data?

hBitmap dd ?


Modifying the resource script :

100 BITMAP "bmp.bmp"

And this one :

invoke  LoadImage,hInstance,100,IMAGE_BITMAP,64,64,0

After building the application, I can see the red ball in the window.
Title: Re: Problems with resource.
Post by: xandaz on November 23, 2019, 08:48:39 PM
    ahhh.... that's right vortex....thanks