无法在程序中包含资源文件

发布于 2024-12-06 06:19:05 字数 8379 浏览 0 评论 0原文

我正在尝试 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
}

我无法在程序中包含资源文件。 我所做的是在主 asm 文件上运行 ml,然后在资源文件上运行 rc,然后将它们链接在一起。程序可以正常编译,但是当我运行程序时,它崩溃了。调试时发现windows找不到资源数据。 德夫吉特

I was trying ICZELION's tutorials and this is my asm program:

.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

Here is my resource file, 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
}

I'm unable to include the resource file in the program.
What i do is run an ml on the main asm file, then an rc on the resource file and then link them together. The program assembles normally, but when i run the program, it crashes. On debugging, i found that windows could not find the resource data.
Devjeet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

节枝 2024-12-13 06:19:05

问题是 .asm 中的 MenuName 定义为:

MenuName BYTE "Name of Menu",0

但在资源文件中它被称为“FirstMenu”。

我怀疑,如果您要将其更改为:

MenuName BYTE "FirstMenu"

http://win32 assembly.online 的示例所示.fr/tut8.html,该程序将运行。

The problem is that the MenuName in your .asm is defined as:

MenuName BYTE "Name of Menu",0

But in your resource file it's called 'FirstMenu'.

I suspect that, if you were to change that to:

MenuName BYTE "FirstMenu"

as shown in the example at http://win32assembly.online.fr/tut8.html, the program will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文