tags:

views:

493

answers:

2

Forgive me for being a complete newbie with Windows DDK.

I have create a simple file named 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;
}

In the same directory I created a sources file like this:

TARGETNAME=test
TARGETTYPE=PROGRAM
TARGETPATH=obj

TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib 

SOURCES= test.cpp

And a makefile like this:

#
# 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

After launching the Windows XP Free Build Environment I browse to the directory with the three files (test.cpp, makefile and sources) and run the following command:

F:\temp\debug\dir1>build -cZg
Which outputs:
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

The problem is that when I run the created executable test.exe it says:

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.

What am I missing here?

+2  A: 

You have compiled a 'native application' rather than a win32 one. The TARGET_TYPE definition controls this.

See 'Inside Native Applications' for a discussion of using the DDK to generate a native application.

Rob Walker
+2  A: 

Rob Walker explains the why but Kernel Mustard explains the how.

Michael Burr
This one got close enough to allow be to do the job. Setting it to accepted even tough it required some tuning.
smink
Can you explain what tuning you needed?
Michael Burr