【问题标题】:crt_printf and ExitProcess in MASM32 with lib带有 lib 的 MASM32 中的 crt_printf 和 ExitProcess
【发布时间】:2015-12-10 18:56:16
【问题描述】:

crt_printf, crt_scanf, ExitProcess

环境路径为 masm32v11r 的 Windows 7

在.asm 文件中,我想调用crt_printf 来打印(或调用ExitProcess 来结束主程序)。但是我的代码是:

.386  
.model flat,stdcall  
option casemap:none  
includelib D:\masm32\lib\msvcrt.lib  
printf proto C:dword,:vararg  
scanf proto C:dword,:vararg

.DATA
print_int    DB "%d",0
print_char   DB "%c",0

我的通话程序是:

PUSH    offset __temp13@_cal@main
PUSH    offset print_string
CALL    crt_printf
ADD     ESP,    8
PUSH    _realCock@main
PUSH    offset print_int
CALL    crt_printf
ADD     ESP,    8
PUSH    offset __temp14@_cal@main

当我点击build All的按钮时,消息会出现:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: D:\masm32\bin\object_code.asm
D:\masm32\bin\object_code.asm(105) : error A2006: undefined symbol : crt_printf
D:\masm32\bin\object_code.asm(109) : error A2006: undefined symbol : crt_printf
D:\masm32\bin\object_code.asm(179) : error A2006: undefined symbol : crt_scanf
D:\masm32\bin\object_code.asm(249) : error A2006: undefined symbol : ExitProcess
Assembly Error

我已经为这样的错误苦苦挣扎了 24 小时,谢谢!

【问题讨论】:

    标签: dll printf masm32


    【解决方案1】:

    crt_printf 是 MASM32 开发人员的一种特殊构造,用于将其与他们的 ma​​cro printf 区分开来。如果您不包含\masm32\macros\macros.asm,则不需要此特殊功能:

    .386
    .model flat,stdcall
    
    includelib \masm32\lib\msvcrt.lib
    includelib \masm32\lib\kernel32.lib
    
    printf proto C :dword, :vararg          ; msvcrt
    ExitProcess proto STDCALL :DWORD        ; kernel32
    
    .DATA
        fmt db "%s",10,0
        hello db "Hello world!",0
    
    .CODE
    main PROC
        push OFFSET hello
        push OFFSET fmt
        call printf
        add esp, (2 * 4)
    
        push 0
        call ExitProcess
    main ENDP
    
    END main
    

    crt_... 别名在msvcrt.inc 中声明:

    .386
    .model flat,stdcall
    
    include \masm32\include\msvcrt.inc
    
    includelib \masm32\lib\msvcrt.lib
    includelib \masm32\lib\kernel32.lib
    
    printf proto C :dword, :vararg          ; msvcrt
    ExitProcess proto STDCALL :DWORD        ; kernel32
    
    .DATA
        fmt db "%s",10,0
        hello db "Hello world!",0
    
    .CODE
    main PROC
        push OFFSET hello
        push OFFSET fmt
        call crt_printf
        add esp, (2 * 4)
    
        push 0
        call ExitProcess
    main ENDP
    
    END main
    

    如果您想要包含所有声明和宏的全部内容,请包含 masm32rt.inc:

    include \masm32\include\masm32rt.inc
    
    .DATA
        fmt db "%s",10,0
        hello db "Hello world!",0
    
    .CODE
    main PROC
        push OFFSET hello
        push OFFSET fmt
        call crt_printf
        add esp, (2 * 4)
    
        printf ("Hello again: %s\n",OFFSET hello);
    
        push 0
        call ExitProcess
    main ENDP
    
    END main
    

    【讨论】:

      猜你喜欢
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多