Я пробовал учебники ICZELION, и это моя программа asm:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
.data
ClassName BYTE "Name of Class",0
MenuName BYTE "Name of Menu",0
TestPrompt BYTE "Test",0
GoodByePrompt BYTE "Good Bye!",0
HelloPrompt BYTE "Hello",0
AppName BYTE "Name Of App",0
.data?
.const
IDM_TEST equ 1
IDM_HELLO equ 2
IDM_GOODBYE equ 3
IDM_EXIT equ 4
.code
main PROC
push SW_SHOWDEFAULT
call GetCommandLine
push eax
push NULL
push NULL
call GetModuleHandle
push eax
call WinMain
push eax
call ExitProcess
main ENDP
WinMain PROC
;[ebp+014h]CmdShow
;[ebp+010h]commandline
;[ebp+0Ch]hPrevInstance
;[ebp+08h]hInstance
push ebp
mov ebp, esp
add esp, 0FFFFFFB0h
mov DWORD PTR [ebp-030h], SIZEOF WNDCLASSEX
mov DWORD PTR [ebp-02Ch], CS_HREDRAW or CS_VREDRAW
mov DWORD PTR [ebp-028h], OFFSET WinProc
mov DWORD PTR [ebp-024h], NULL
mov DWORD PTR [ebp-020h], NULL
push DWORD PTR [ebp+08h]
pop DWORD PTR [ebp-0Ch]
push IDI_APPLICATION
push NULL
call LoadIcon
mov DWORD PTR [ebp-018h], eax
mov DWORD PTR [ebp-04h], eax
push IDC_ARROW
push NULL
call LoadCursor
mov DWORD PTR [ebp-014h], eax
mov DWORD PTR [ebp-010h], COLOR_WINDOW
mov DWORD PTR [ebp-0Ch], OFFSET MenuName
mov DWORD PTR [ebp-08h], OFFSET ClassName
lea eax, DWORD PTR [ebp-030h]
push eax
call RegisterClassEx
push NULL
push [ebp+08h]
push NULL
push NULL
push 400
push 400
push 200
push 200
push WS_OVERLAPPEDWINDOW
push OFFSET AppName
push OFFSET ClassName
push NULL
call CreateWindowEx
mov [ebp-050h], eax
;display and update the window
push [ebp+014h]
push [ebp-050h]
call UpdateWindow
push [ebp-050h]
call ShowWindow
_MessageLoop:
push NULL
push NULL
push [ebp-050h]
push [ebp-04Ch]
call GetMessage
cmp eax, 0FFFFFFFFh
je _ExitMessageLoop
lea eax, DWORD PTR [ebp-04Ch]
push eax
call TranslateMessage
lea eax, DWORD PTR [ebp-04Ch]
push eax
call DispatchMessage
jmp _MessageLoop
_ExitMessageLoop:
mov eax, [ebp-044h]
mov esp,ebp
pop ebp
ret 010h
WinMain ENDP
WinProc PROC
;[ebp+014h]lParam
;[ebp+010h]wParam
;[ebp+0Ch]uMsg
;[ebp+08h]hWnd
push ebp
mov ebp, esp
cmp DWORD PTR[ebp+0ch], WM_DESTROY
je _WMDESTROY
cmp DWORD PTR [ebp+0Ch], WM_COMMAND
je _WMCOMMAND
_WMDESTROY:
push NULL
call PostQuitMessage
_WMCOMMAND:
mov eax, [ebp+0Ch]
cmp al, IDM_TEST
je _test
cmp al, IDM_HELLO
je _hello
cmp al, IDM_GOODBYE
je _goodbye
cmp al, IDM_EXIT
je _exit
jmp _ExitWmCommand
_test:
push MB_OK
push OFFSET AppName
push OFFSET TestPrompt
push NULL
call MessageBox
jmp _ExitWmCommand
_hello:
push MB_OK
push OFFSET AppName
push OFFSET HelloPrompt
push NULL
call MessageBox
jmp _ExitWmCommand
_goodbye:
push MB_OK
push OFFSET AppName
push OFFSET GoodByePrompt
push NULL
call MessageBox
jmp _ExitWmCommand
_exit:
push [ebp+08h]
call DestroyWindow
_ExitWmCommand:
push DWORD PTR [ebp+014h]
push DWORD PTR [ebp+010h]
push DWORD PTR [ebp+0Ch]
push DWORD PTR [ebp+08h]
call DefWindowProc
xor eax, eax
pop ebp
ret 010h
WinProc ENDP
END main
Вот мой файл ресурсов, mainprog.rc:
#define IDM_TEST 1
#define IDM_HELLO 2
#define IDM_GOODBYE 3
#define IDM_EXIT 4
FirstMenu MENU
{
POPUP "&PopUp"
{
MENUITEM "&SayHello", IDM_HELLO
MENUITEM "&SayGoodBye",IDM_GOODBYE
MENUITEM SEPARATOR
MENUITEM "&Exit",IDM_EXIT
}
MENUITEM "&Test", IDM_TEST
}
Я не могу включить файл ресурсов в программу.
Что я делаю, это запускаю ml в главном файле asm, затем rc в файле ресурсов и затем связываю их вместе. Программа собирается нормально, но при запуске программы происходит сбой. При отладке я обнаружил, что окна не могут найти данные ресурса.
Devjeet