阅读:3092回复:5
编译最简单例子 出错,,求救
按照最基本的例子,写好了,可是编译时出错,请帮忙
Current DDK Directory = D:\WINDDK\2600 Building for i386 ******Configuration: wdmTemp - Win32 Debug ************* D:\pj\temp\wdmTemp>call D:\WINDDK\2600\bin\setenv.bat D:\WINDDK\2600 chk D:\pj\temp\wdmTemp>build.exe -ceZ BUILD: Object root set to: ==> objchk BUILD: Adding /Y to COPYCMD so xcopy ops won't hang. BUILD: /i switch ignored BUILD: Compile and Link for i386 BUILD: Examining d:\pj\temp\wdmtemp directory for files to compile. d:\pj\temp\wdmtemp BUILD: Compiling d:\pj\temp\wdmtemp directory Compiling - helloworld.cpp for i386 d:\winddk\2600\inc\ddk\wxp\ntddk.h(2152) : error C2220: warning treated as error - no object file generated d:\winddk\2600\inc\ddk\wxp\ntddk.h(2152) : error C4162: '_ReturnAddress' : no function with C linkage found d:\winddk\2600\inc\ddk\wxp\ntddk.h(6852) : error C4162: '_InterlockedExchange' : no function with C linkage found d:\winddk\2600\inc\ddk\wxp\ntddk.h(6878) : error C4162: '_InterlockedIncrement' : no function with C linkage found d:\winddk\2600\inc\ddk\wxp\ntddk.h(6891) : error C4162: '_InterlockedDecrement' : no function with C linkage found d:\winddk\2600\inc\ddk\wxp\ntddk.h(6905) : error C4162: '_InterlockedExchangeAdd' : no function with C linkage found d:\winddk\2600\inc\ddk\wxp\ntddk.h(6935) : error C4162: '_InterlockedCompareExchange' : no function with C linkage found d:\winddk\2600\inc\ddk\wxp\ntddk.h(6987) : error C4162: '_InterlockedOr' : no function with C linkage found d:\winddk\2600\inc\ddk\wxp\ntddk.h(6997) : error C4162: '_InterlockedAnd' : no function with C linkage found d:\winddk\2600\inc\ddk\wxp\ntddk.h(7007) : error C4162: '_InterlockedXor' : no function with C linkage found BUILD: Compile errors: not linking d:\pj\temp\wdmtemp directory BUILD: Done //////////////////////////////////////////////////////////////////////////////////////// xp+winxpddk+ds3.2 +vcsp6 结果就这样报错 代码如下 #ifndef __HELLOWORLD_C__ #define __HELLOWORLD_C__ #define DEBUGMSG #include "helloWorld.h" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath) { NTSTATUS ntStatus=STATUS_SUCCESS; PDEVICE_OBJECT IpDeviceObject=NULL; UNICODE_STRING DeviceNameString; UNICODE_STRING DeviceLinkString; #ifdef DEBUGMSG DbgPrint("hi, Starting DriverEntry()\n"); #endif RtlInitUnicodeString(&DeviceNameString,NT_DEVICE_NAME); ntStatus=IoCreateDevice(DriverObject,0,&DeviceNameString,FILE_DEVICE_UNKNOWN,0,FALSE,&IpDeviceObject); if(!NT_SUCCESS(ntStatus)) { #ifdef DEBUGMSG DbgPrint("hi, Error IoCreateDevice()\n"); #endif goto Error; } RtlInitUnicodeString(&DeviceLinkString,DOS_DEVICE_NAME); ntStatus=IoCreateSymbolicLink(&DeviceLinkString,&DeviceNameString); if(!NT_SUCCESS(ntStatus)) { #ifdef DEBUGMSG DbgPrint("hi, Error IoCreateSymbolicLink()\n"); #endif goto Error; } DriverObject->MajorFunction[IRP_MJ_CREATE]=HelloWorldDispatch; DriverObject->MajorFunction[IRP_MJ_CLOSE]=HelloWorldDispatch; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=HelloWorldDispatch; DriverObject->DriverUnload=HelloWorldUnload; return ntStatus; Error: #ifdef DEBUGMSG DbgPrint("hi, Error DriverEntry()\n"); #endif return ntStatus; } NTSTATUS HelloWorldDispatch(IN PDEVICE_OBJECT DeviceObject,IN PIRP pIrp) { NTSTATUS ntStatus=STATUS_SUCCESS; ULONG IoControlCodes=0; PIO_STACK_LOCATION IrpStack=NULL; pIrp->IoStatus.Status=STATUS_SUCCESS; pIrp->IoStatus.Information=0; #ifdef DEBUGMSG DbgPrint("hi, Starting HelloWorldDispatch()\n"); #endif IrpStack=IoGetCurrentIrpStackLocation(pIrp); switch(IrpStack->MajorFunction) { case IRP_MJ_CREATE: #ifdef DEBUGMSG DbgPrint("hi, IRP_MJ_CREATE\n"); #endif break; case IRP_MJ_CLOSE: #ifdef DEBUGMSG DbgPrint("hi, IRP_MJ_CLOSE\n"); #endif break; case IRP_MJ_DEVICE_CONTROL: #ifdef DEBUGMSG DbgPrint("hi, IRP_MJ_DEVICE_CONTROL\n"); #endif IoControlCodes=IrpStack->Parameters.DeviceIoControl.IoControlCode; switch(IoControlCodes) { case START_HELLOWORLD: DbgPrint("hi, Starting \"Hello World \"\n"); break; case STOP_HELLOWORLD: DbgPrint("hi, Stoping \"Hello World \"\n"); break; default: pIrp->IoStatus.Status=STATUS_INVALID_PARAMETER; break; } break; default: break; } ntStatus=pIrp->IoStatus.Status; IoCompleteRequest(pIrp,IO_NO_INCREMENT); return ntStatus; } VOID HelloWorldUnload(IN PDRIVER_OBJECT DriverObject) { UNICODE_STRING DeviceLinkString; PDEVICE_OBJECT DeviceObjectTemp1=NULL; PDEVICE_OBJECT DeviceObjectTemp2=NULL; #ifdef DEBUGMSG DbgPrint("hi,Starting HelloWorldUnload()\n"); #endif RtlInitUnicodeString(&DeviceLinkString,DOS_DEVICE_NAME); IoDeleteSymbolicLink(&DeviceLinkString); if(DriverObject) { DeviceObjectTemp1=DriverObject->DeviceObject; while(DeviceObjectTemp1) { DeviceObjectTemp2=DeviceObjectTemp1; DeviceObjectTemp1=DeviceObjectTemp1->NextDevice; IoDeleteDevice(DeviceObjectTemp2); } } } #endif /////////////////////////////////////////////////////////////////////////////////////////////// //#ifndef __HELLOWORLD_H__ //#define __HELLOWORLD_H__ #include <ntddk.h> #define DEVICE_HELLO_INDEX 0x860 #define START_HELLOWORLD CTL_CODE(FILE_DEVICE_UNKNOWN,DEVICE_HELLO_INDEX,METHOD_BUFFERED,FILE_ANY_ACCESS) #define STOP_HELLOWORLD CTL_CODE(FILE_DEVICE_UNKNOWN,DEVICE_HELLO_INDEX+1,METHOD_BUFFERED,FILE_ANY_ACCESS) #define NT_DEVICE_NAME L"\\Device\\HelloWorld" #define DOS_DEVICE_NAME L"\\DosDevices\\HelloWorld" NTSTATUS HelloWorldDispatch(IN PDEVICE_OBJECT DeviceObject,IN PIRP pIrp); VOID HelloWorldUnload(IN PDRIVER_OBJECT DriverObject); //#endif |
|
沙发#
发布于:2008-03-27 21:49
我也遇到同样的问题,楼主解决没?
|
|
板凳#
发布于:2008-04-23 09:21
你肯定源码是HelloWorld.c不是HelloWorld.cpp吗?如果是.cpp问题出在extern "C"上,.h中应该是extern "C" {#include "ntddk.h"} .cpp中应该在DriverEntry前面加个 extern "C"
|
|
地板#
发布于:2008-05-07 19:52
恩,楼上的那位说的很对,的确是这样的,解释一下原因,可以么!
|
|
地下室#
发布于:2008-05-12 10:44
引用第2楼chaosuper于2008-04-23 09:21发表的 :
这句就不要了吧? |
|
5楼#
发布于:2008-05-14 01:44
extern "C"是表示“用C链接”,你是HelloWorld.c就不需要了
|
|