News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Iczelion Tutorial 8 help!!!!

Started by EnFeR RoI, February 20, 2010, 06:05:56 AM

Previous topic - Next topic

EnFeR RoI

Hello coders,

I am slightly confuse in link the resource file with source code as i  don't know how to link resorce file with source code.
Here is a step by step of coding done by me:-

1)First of all, i write a coding of menu and save the file as a D:\masm32\ton.asm.Here is a code:-

.386
.model flat,stdcall
option casemap:none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
ClassName db "SimpleWinClass",0
AppName  db "Our First Window",0
MenuName db "FirstMenu",0                ; The name of our menu in the resource file.
Test_string db "You selected Test menu item",0
Hello_string db "Hello, my friend",0
Goodbye_string db "See you again, bye",0

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?

.const
IDM_TEST equ 1                    ; Menu IDs
IDM_HELLO equ 2
IDM_GOODBYE equ 3
IDM_EXIT equ 4

.code
start:
    invoke GetModuleHandle, NULL
    mov    hInstance,eax
    invoke GetCommandLine
    mov CommandLine,eax
    invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
    invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
    mov   wc.cbSize,SIZEOF WNDCLASSEX
    mov   wc.style, CS_HREDRAW or CS_VREDRAW
    mov   wc.lpfnWndProc, OFFSET WndProc
    mov   wc.cbClsExtra,NULL
    mov   wc.cbWndExtra,NULL
    push  hInst
    pop   wc.hInstance
    mov   wc.hbrBackground,COLOR_WINDOW+1
    mov   wc.lpszMenuName,OFFSET MenuName        ; Put our menu name here
    mov   wc.lpszClassName,OFFSET ClassName
    invoke LoadIcon,NULL,IDI_APPLICATION
    mov   wc.hIcon,eax
    mov   wc.hIconSm,eax
    invoke LoadCursor,NULL,IDC_ARROW
    mov   wc.hCursor,eax
    invoke RegisterClassEx, addr wc
    invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
    mov   hwnd,eax
    invoke ShowWindow, hwnd,SW_SHOWNORMAL
    invoke UpdateWindow, hwnd
    .WHILE TRUE
                invoke GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                invoke DispatchMessage, ADDR msg
    .ENDW
    mov     eax,msg.wParam
    ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    .IF uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL
    .ELSEIF uMsg==WM_COMMAND
        mov eax,wParam
        .IF ax==IDM_TEST
            invoke MessageBox,NULL,ADDR Test_string,OFFSET AppName,MB_OK
        .ELSEIF ax==IDM_HELLO
            invoke MessageBox, NULL,ADDR Hello_string, OFFSET AppName,MB_OK
        .ELSEIF ax==IDM_GOODBYE
            invoke MessageBox,NULL,ADDR Goodbye_string, OFFSET AppName, MB_OK
        .ELSE
            invoke DestroyWindow,hWnd
        .ENDIF
    .ELSE
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
    .ENDIF
    xor    eax,eax
    ret
WndProc endp
end start


2) After saving the file of menu in d:\masm32\ton.asm, i open a new windows in qeditor for writing a code of resource file i.e:-

#define IDM_TEST 1
#define IDM_HELLO 2
#define IDM_GOODBYE 3
#define IDM_EXIT 4

FirstMenu MENU
{
POPUP "&PopUp"
        {
         MENUITEM "&Say Hello",IDM_HELLO
         MENUITEM "Say &GoodBye", IDM_GOODBYE
         MENUITEM SEPARATOR
         MENUITEM "E&xit",IDM_EXIT
        }
MENUITEM "&Test", IDM_TEST
}
 


3) I assemble the ton.asm file and it show no error :bg

4) Then i confused what i should do to combine ton.asm and ton.rc file to make a executable file as in iczelion tutorial there is no hint show in linking of resource file with source code to make .exe file????

Hope you reply soon!!!
EnFeR RoI.

BlackVortex

After you assemble your source you get an .obj file.
After using rc.exe (resource compiler) on your .rc file THEN you get a .res file.
Finally you use the linker (link.exe) to make the exe file. Use the res file as a parameter.

Aren't there make.bat files included with some tutorials by Iczelion ? Fine an example with resources and see how he compiles them.

EnFeR RoI

Helo BlackVortex,

Thanks for the reply, but i want to ask that you write
Quote
After using rc.exe (resource compiler) on your .rc file THEN you get a .res file.

Is resource compiler is already given in masm32 folder or i have to download that resource compiler and where i get this resource compiler so that i get .res file???

Thanks once again BlackVortex.
EnFeR RoI.

BlackVortex

masm32 contains "rc.exe" in the same folder as ml.exe and link.exe

If you can't get it to work, post your commands and the console output.

EnFeR RoI

What is the code of linking of rc file to make .res file???

Here what i do the command:-

1) ml  /c /coff /Cp ton.asm

Assemble happily! :bg

2) link /SUBSYSTEM:WINDOWS /LIBPATH:d:\masm32\lib d:\masm32\ton.obj

Link succesfully :bg

3) Now how to use rc.exe to combine resource file with source code in command prompt??
Please write down the code in command prompt to clear the problem...

If I make a mistake then please correct the mistake and help me out with this irritating problem :'(

Thanks in advance.
EnFeR RoI.

BlackVortex

You didn't follow my steps correctly ! Linking is the last thing to do.

First do (assuming your reource file is named rsrc.rc)
rc rsrc.rc
(to get a rsrc.res file)

and at the end do :
link /SUBSYSTEM:WINDOWS /LIBPATH:d:\masm32\lib d:\masm32\ton.obj rsrc.res

EnFeR RoI

Finally I got a result of .res file and link it successfully and got menu.exe file :dance:
Thanks a lot BlackVortex Sir to help me out for solving my problem!!!

Thanks once again BlackVortex :U
EnFeR RoI.

BlackVortex

Cool  :8)

Just as a little bonus, now that you have a resource section, you can also add an .ico file for example.   :green2
Add this line to your rsrc.rc
IDR_ICON ICON DISCARDABLE "youricon.ico"
and put an ico file in the same folder.

Note that you will have to recompile your resources every time you change them.

EnFeR RoI