请原谅我是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

这样的 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.

我在这里缺少什么?

有帮助吗?

解决方案

Rob Walker 解释了原因,但内核芥末解释了如何。

其他提示

您已编译了“本机应用程序”而不是win32。 TARGET_TYPE定义控制了这一点。

有关使用的讨论,请参阅“内部原生应用程序” DDK生成本机应用程序。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top