首页 文章

Windows CE的汇编语言

提问于
浏览
2

如何用Windows CE(x86)的汇编语言编写程序?现在我正在使用VS2008 winth Windows CE 5.0 SDK,我的C程序运行正常 . 我尝试使用我的代码创建一个asm文件并将其包含在项目中:

#include "stdafx.h"
#include "windows.h"
extern "C" void clear(); 


int _tmain(int argc, _TCHAR* argv[])
{
    clear(); 
    return 0;
}

clear.asm:

.586              ;Target processor.  Use instructions for Pentium class machines
.MODEL FLAT, C    ;Use the flat memory model. Use C calling conventions
.STACK            ;Define a stack segment of 1KB (Not required for this example)
.DATA             ;Create a near data segment.  Local variables are declared after
                  ;this directive (Not required for this example)
.CODE             ;Indicates the start of a code segment.

clear PROC
   xor eax, eax 
   xor ebx, ebx 
   ret 
clear ENDP 
END

一切顺利,直到我想调用WinApi函数(MessageBox)形式的asm代码 .

.DATA ;Create a near data segment. Local variables are declared after

    szMessageText       DB  "Hello world text", 0
    szMessageCaption    DB  "HWorld capt, 0

    .CODE ;Indicates the start of a code segment.
    clear PROC
    Invoke MessageBox, NULL, ADDR szMessageText, ADDR szMessageCaption, MB_OK
    clear ENDP
    END

它给

错误A2006:未定义的符号:MessageBox

我为MASM添加了包含Windows CE SDK库的包含路径:

C:\ Program Files \ Windows CE Tools \ wce500 \ STANDARDSDK_500 \ Lib \ x86

并试图包括coredll.lib,但没有效果

includelib coredll.lib

所以主要问题是: Where is my mistake? Can I write asm code with winapi functions?

Thaks for your answers!

-----------------------------------------------

UPD: 谢谢大家 . 我设法通过编写一个函数的proto defenition来构建项目:

MessageBoxW PROTO hwnd:DWORD,lpText:DWORD,lpCaption:DWORD,uType:DWORD

我怎样才能避免为我将要使用的每个函数编写这样的原型?据我所知,我需要.inc文件与proto defenitions的功能?或者以某种方式使用.h文件中的函数定义?

1 回答

  • 3
    Invoke MessageBox, NULL, ADDR szMessageText, ADDR szMessageCaption, MB_OK
    

    winapi中没有名为MessageBox的函数 . MessageBoxA是一个遗留函数,它采用8位编码字符串,MessageBoxW是一个采用utf-16编码字符串的函数 . 当您在C中编写代码时,这通常是不可见的,预处理器会根据您是否已定义UNICODE预处理程序符号自动转换函数名称 .

    在汇编中编写代码时没有这样的帮助,你很快就会发现 . 背景资料MSDN文章是available here .

相关问题