代码之家  ›  专栏  ›  技术社区  ›  Jorge Ferreira

使用Windows DDK编译时出错

  •  1
  • Jorge Ferreira  · 技术社区  · 16 年前

    请原谅我是一个使用Windows DDK的新手。

    我已经创建了一个名为 test.cpp :

    #include <windows.h>
    
    #define BAD_ADDRESS 0xBAADF00D
    
    int __cdecl main(int argc, char* args[])
    {
        char* p =(char*)BAD_ADDRESS;
        *p='A';
        return 0;
    }
    

    在同一个目录中,我创建了一个 sources 像这样的文件:

    TARGETNAME=test
    TARGETTYPE=PROGRAM
    TARGETPATH=obj
    
    TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib 
    
    SOURCES= test.cpp
    

    和A makefile 这样地:

    #
    # DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source
    # file to this component.  This file merely indirects to the real make file
    # that is shared by all the components of Windows
    #
    !INCLUDE $(NTMAKEENV)\makefile.def
    

    启动Windows XP免费生成环境后,我用三个文件(test.cpp、makefile和sources)浏览到目录,并运行以下命令:

    F:\temp\debug\dir1>build -cZg

    输出:

    BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
    BUILD: Using 2 child processes
    BUILD: Object root set to: ==> objfre_wxp_x86
    BUILD: Compile and Link for i386
    BUILD: Examining f:\temp\debug\dir1 directory for files to compile.
    BUILD: Compiling (NoSync) f:\temp\debug\dir1 directory
    1>Compiling - test.cpp for i386
    BUILD: Compiling  f:\temp\debug\dir1 directory
    BUILD: Linking f:\temp\debug\dir1 directory
    1>Linking Executable - objfre_wxp_x86\i386\test.exe for i386
    BUILD: Done
    
        2 files compiled
        1 executable built
    

    问题是当我运行创建的可执行文件时 test.exe 它说:

    F:\temp\debug\dir1\objfre_wxp_x86\i386>test
    The F:\temp\debug\dir1\objfre_wxp_x86\i386\test.exe application cannot be run in Win32 mode.
    

    我这里缺什么?

    2 回复  |  直到 16 年前
        1
  •  2
  •   Community CDub    8 年前

    Rob Walker 解释了原因,但是 Kernel Mustard 解释方法。

        2
  •  3
  •   Rob Walker    16 年前

    您编译了“本机应用程序”而不是Win32应用程序。目标类型定义控制了这一点。

    Inside Native Applications '讨论如何使用DDK生成本机应用程序。