locked
list files in a directory on kdbg console RRS feed

  • Question

  • this is a small code in witch i want to  pass the handle of directory to ZwCreateFile. 

    It shows me an Error:C2220 .... can someone please help me out???

     #include <wdm.h>
    #include <windef.h>
    #include <ntddk.h>
    #include <Ntdef.h>
    
    //===========================================================================
    DRIVER_INITIALIZE DriverEntry;
    DRIVER_UNLOAD Unload;
    NTSTATUS status;
    
    HANDLE hdir;
    IO_STATUS_BLOCK iosb;
    
    OBJECT_ATTRIBUTES oa = { sizeof(oa), NULL, L"c://", OBJ_CASE_INSENSITIVE, NULL, NULL };  
    
    //===========================================================================
    NTSTATUS DriverEntry(
    			__in struct _DRIVER_OBJECT  *DriverObject,
    			__in PUNICODE_STRING  RegistryPath 
    			)
    {
    	DbgPrint("\ndriver loaded\n\n\n");
    
    	status = ZwCreateFile(
    				&hdir, 
    				FILE_LIST_DIRECTORY, 
    				&oa, 
    				&iosb, 
    				NULL, 
    				FILE_ATTRIBUTE_NORMAL,
    				0,					//FILE_SHARE_READ,
    				FILE_OPEN, 
    				FILE_DIRECTORY_FILE,
    				NULL, 
    				0
    				);
    
    	if (status != STATUS_SUCCESS)
    	{
    		DbgPrint("\nZwCreateFile error");
    		goto end;
    	}
    
    	DbgPrint("\nZwCreateFile success");
    
    
    
    end:
    DriverObject->DriverUnload = Unload;
    return STATUS_SUCCESS;
    }
    
    //===========================================================================
    VOID Unload(
    		__in struct _DRIVER_OBJECT  *DriverObject
    		)
    {
    	DbgPrint("\ndriver unloaded");
    	
    //return STATUS_SUCCESS;	
    }
    
    
    
    • Edited by daweed69 Tuesday, June 18, 2013 4:27 PM
    Tuesday, June 18, 2013 4:20 PM

Answers

  • Well you are using a pointer to a string when the structure needs a UNICODE_STRING pointer.  UNICODE_STRING is a structure in itself.  So, use something like

    UNICODE_STRING DirPath = RTL_CONSTANT_STRING( L"c://" );

    OBJECT_ATTRIBUTES oa = { sizeof(oa), NULL, &DirPart, OBJ_CASE_INSENSITIVE, NULL, NULL }; 

    In general you need to look at the warning messages, since this would have been pointed out to you.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, June 18, 2013 5:32 PM
  • C2220 is the error to indicate /WX is on which changes warnings to errors.  Fix your warnings, for instance add the UNREFERENCED_PARAMETER( DriverObject ); to the unload routine.  Do not just disable /WX since a lot of those warnings can represent real problems, and a bug in a driver is a crash most of the time.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, June 18, 2013 4:26 PM
  • You can't include winbase.h or any other user space (i.e. from the API directory) include file.   Take a sources file from a simple WDK project, change the name to the file you showed as your code and retry this.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Wednesday, June 19, 2013 11:08 PM

All replies

  • C2220 is the error to indicate /WX is on which changes warnings to errors.  Fix your warnings, for instance add the UNREFERENCED_PARAMETER( DriverObject ); to the unload routine.  Do not just disable /WX since a lot of those warnings can represent real problems, and a bug in a driver is a crash most of the time.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, June 18, 2013 4:26 PM
  • OBJECT_ATTRIBUTES oa = { sizeof(OBJECT_ATTRIBUTES), NULL, L"c://", OBJ_CASE_INSENSITIVE, NULL, NULL }; 
    It is showing an error at this line :: error C2220
    • Edited by daweed69 Tuesday, June 18, 2013 5:33 PM
    Tuesday, June 18, 2013 5:23 PM
  • Well you are using a pointer to a string when the structure needs a UNICODE_STRING pointer.  UNICODE_STRING is a structure in itself.  So, use something like

    UNICODE_STRING DirPath = RTL_CONSTANT_STRING( L"c://" );

    OBJECT_ATTRIBUTES oa = { sizeof(oa), NULL, &DirPart, OBJ_CASE_INSENSITIVE, NULL, NULL }; 

    In general you need to look at the warning messages, since this would have been pointed out to you.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, June 18, 2013 5:32 PM
  • how to i load 
    ZwQueryDirectoryFile 
    into my code ? 
    Wednesday, June 19, 2013 11:00 AM
  • How are you building your driver?  If you are using the Win8 WDK then you should have a driver project and the settings will be there.   If you are using the Win7 WDK you should be using the BUILD environment.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Wednesday, June 19, 2013 11:06 AM
  • i am using build environment 

    Wednesday, June 19, 2013 1:17 PM
  • #include <wdm.h>
    #include <windef.h>
    #include <ntddk.h>
    #include <Ntdef.h>
    #include <Ntifs.h>
    //#include <fltkernel.h>
    
    //===========================================================================
    struct FBDI {
      ULONG  NextEntryOffset;
      ULONG  FileIndex;
      LARGE_INTEGER  CreationTime;
      LARGE_INTEGER  LastAccessTime;
      LARGE_INTEGER  LastWriteTime;
      LARGE_INTEGER  ChangeTime;
      LARGE_INTEGER  EndOfFile;
      LARGE_INTEGER  AllocationSize;
      ULONG  FileAttributes;
      ULONG  FileNameLength;
      ULONG  EaSize;
      CCHAR  ShortNameLength;
      WCHAR  ShortName[12];
      WCHAR  FileName[1];
    }*pbInfo, fbdi_size;
    
    
    //===========================================================================
    DRIVER_INITIALIZE DriverEntry;
    DRIVER_UNLOAD Unload;
    NTSTATUS status;
    
    
    //IO_STATUS_BLOCK iostatusblock;
    //OBJECT_ATTRIBUTES objattr = { sizeof(OBJECT_ATTRIBUTES), NULL, L"c://" , OBJ_CASE_INSENSITIVE, NULL, NULL };  
    
    
    
    
    //===========================================================================
    NTSTATUS DriverEntry(
    			__in struct _DRIVER_OBJECT  *DriverObject,
    			__in PUNICODE_STRING  RegistryPath 
    			)
    {
    	HANDLE hdir;
    	UNICODE_STRING DirPath = RTL_CONSTANT_STRING( L"\\??\\C:\\" );
    	OBJECT_ATTRIBUTES objattr;
    	IO_STATUS_BLOCK iostatusblock;
    
    
    	unsigned int uSize  = sizeof(fbdi_size);
    	
    	InitializeObjectAttributes(&objattr, &DirPath, OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE, NULL,NULL);
    
    	BOOLEAN bIsStarted  = TRUE;
    
    
    
    
    	DbgPrint("\n\ndriver loaded");
    
    	status = ZwCreateFile(
    				&hdir, 
    				FILE_LIST_DIRECTORY,	// | GENERIC_READ | SYNCHRONIZE, //FILE_LIST_DIRECTORY, 
    				&objattr, 
    				&iostatusblock, 
    				NULL, 
    				FILE_ATTRIBUTE_NORMAL,
    				FILE_SHARE_READ, 					//FILE_SHARE_READ,
    				FILE_OPEN,		//FILE_ATTRIBUTE_READONLY, 
    				FILE_DIRECTORY_FILE,	// | FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE, //FILE_DIRECTORY_FILE,
    				NULL, 
    				0
    				);
    
    	if (status != STATUS_SUCCESS)
    	{
    		DbgPrint("\nZwCreateFile error::%X", status);
    		ZwClose(hdir);
    		goto end;
    	}
    
    	else
    	{
    		DbgPrint("\nZwCreateFile success");
    
    		status = ZwQueryDirectoryFile(
    						hdir,
    						0,
    						NULL, 
    						NULL, 
    						&iostatusblock, 
    						&pbInfo, 
    						uSize,
    						FileDirectoryInformation, 
    						FALSE, 
    						NULL,
    						bIsStarted);
    		if (status != STATUS_SUCCESS) 
    		{
    			DbgPrint("\n\nZwQueryDirectoryFile error::%X", status);
    			ZwClose(hdir);
    			goto Break; 
    		}
    
    		else
    		{
    			DbgPrint("\n\nZwQueryDirectoryFile success");
    			ZwClose(hdir);
    			goto Break;
    		}	   
    			 
    	}
    
    
    
    
    
    Break:
    end:
    DriverObject->DriverUnload = Unload;
    return STATUS_SUCCESS;
    }
    
    
    //===========================================================================
    VOID Unload(
    		__in struct _DRIVER_OBJECT  *DriverObject
    		)
    {
    	DbgPrint("\ndriver unloaded");
    	
    
    //return STATUS_SUCCESS;	
    }

    this is my code .... i am trying to list the files in the directory ....


    • Edited by daweed69 Wednesday, June 19, 2013 2:30 PM header file
    Wednesday, June 19, 2013 1:35 PM
  • Then your driver should be linked properly to call ZwQueryDirectoryFile.  I guess I don't know what you are asking.  Does your driver build properly?  Do you need help loading the driver? Please elaborate.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Wednesday, June 19, 2013 3:44 PM
  • #include <wdm.h>
    #include <windef.h>
    #include <ntddk.h>
    #include <Ntifs.h>
    #include <fltkernel.h>
    
    
    //===========================================================================
    DRIVER_INITIALIZE DriverEntry;
    DRIVER_UNLOAD Unload;
    NTSTATUS status, QDFstatus;
    
    
    //===========================================================================
    NTSTATUS DriverEntry(
    			__in struct _DRIVER_OBJECT  *DriverObject,
    			__in PUNICODE_STRING  RegistryPath 
    			)
    {
    	HANDLE hdir;
    	UNICODE_STRING DirPath = RTL_CONSTANT_STRING( L"\\??\\C:\\" );
    	OBJECT_ATTRIBUTES objattr = {0};
    	IO_STATUS_BLOCK iostatusblock = {};
    	FILE_BOTH_DIR_INFORMATION *pbInfo = NULL;
    
    
    	UINT uSize  = sizeof(FILE_BOTH_DIR_INFORMATION);
    	BOOLEAN bIsStarted  = TRUE;
    	
    	InitializeObjectAttributes(&objattr, &DirPath, OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE, NULL,NULL);
    
    	DbgPrint("\n\ndriver loaded");
    
    	status = ZwCreateFile(
    				&hdir, 
    				FILE_LIST_DIRECTORY,	// | GENERIC_READ | SYNCHRONIZE, //FILE_LIST_DIRECTORY, 
    				&objattr, 
    				&iostatusblock, 
    				NULL, 
    				FILE_ATTRIBUTE_NORMAL,
    				FILE_SHARE_READ, 					//FILE_SHARE_READ,
    				FILE_OPEN,		//FILE_ATTRIBUTE_READONLY, 
    				FILE_DIRECTORY_FILE,	// | FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE, //FILE_DIRECTORY_FILE,
    				NULL, 
    				0
    				);
    
    	if (status != STATUS_SUCCESS)
    	{
    		DbgPrint("\nZwCreateFile error::%X", status);
    		ZwClose(hdir);
    		goto Break;
    
    		goto end;
    	}
    
    	else											//parent else
    	{
    		DbgPrint("\nZwCreateFile success");
    
    		pbInfo = (FILE_BOTH_DIR_INFORMATION*)ExAllocatePoolWithTag(PagedPool, uSize, '0000');
    		if (pbInfo == NULL)
    		{
    			DbgPrint("\npointer to fileinfo failed");
    			ZwClose(hdir);
    			goto Break;
    		}
    
    		while(TRUE)									//parent while					
    		{
    			dir_search:
    
    			RtlZeroMemory(pbInfo, uSize);
    			
    			QDFstatus = ZwQueryDirectoryFile(
    							hdir,
    							0,
    							NULL, 
    							NULL, 
    							&iostatusblock, 
    							&pbInfo, 
    							uSize,
    							FileDirectoryInformation, 
    							FALSE, 
    							NULL,
    							bIsStarted);
    			if (QDFstatus == STATUS_BUFFER_OVERFLOW) 
    			{
    				ExFreePoolWithTag(pbInfo, '000');
    				uSize = uSize * 2;
    				pbInfo = (FILE_BOTH_DIR_INFORMATION*)ExAllocatePoolWithTag(PagedPool, uSize, '0000');
    
    				if (pbInfo == NULL)
    				{
    					DbgPrint("\nQDFstatus pointer to fileinfo failed");
    					ZwClose(hdir);
    					return STATUS_NO_MEMORY;
    				}
    
    				goto dir_search;
    			}
    
    			else if( QDFstatus == STATUS_NO_MORE_FILES  )
    			{
    				DbgPrint("\nno more files in directory");
    				ExFreePoolWithTag(pbInfo, '000');
    				ZwClose(hdir);
    				goto Break;
    			}
    
    			else if( QDFstatus != STATUS_SUCCESS )
    			{
    				DbgPrint("\nQDFstatus Failed");
    				ExFreePoolWithTag(pbInfo, '000');
    				ZwClose(hdir);
    				goto Break;
    			}
    
    			if (bIsStarted)
    			{
    				bIsStarted = FALSE;
    			}
    
    			DbgPrint("\nFILENAMES IN C://");
    			while (TRUE)								//child while
    			{
    				WCHAR *FileName = (WCHAR*)ExAllocatePoolWithTag(PagedPool,(pbInfo->FileNameLength + sizeof(WCHAR)), '0001');
    
    				if(FileName)
    				{
    					RtlZeroMemory(FileName, (pbInfo->FileNameLength + sizeof(WCHAR)));
    					RtlCopyMemory(FileName, pbInfo->FileName, pbInfo->FileNameLength);
    
    					DbgPrint("\n%s", FileName);
    					
    					ExFreePoolWithTag(FileName, '000');
    					if (pbInfo->NextEntryOffset == 0)
    					{
    						break;
    					}
    
    					pbInfo += pbInfo->NextEntryOffset;
    				}
    
    
    			 }									//child while
    
    		}										//end parent while
    			 
    	}											//end parent else
    
    
    
    
    
    Break:
    end:
    DriverObject->DriverUnload = Unload;
    return STATUS_SUCCESS;
    }
    
    
    //===========================================================================
    VOID Unload(
    		__in struct _DRIVER_OBJECT  *DriverObject
    		)
    {
    	DbgPrint("\ndriver unloaded");
    	
    
    //return STATUS_SUCCESS;	
    }
    

    no i am unable to build it. please can u help me

    i am using

    Windows Driver kit on a 32bit operating system

     
    Wednesday, June 19, 2013 6:23 PM
  • What is the failure?  Grab the output of the build environment window from the command "build -cefbw" and post that here.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Wednesday, June 19, 2013 6:38 PM
  • 1>errors in directory c:\simple_driver\driver\driver
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(318) : error C2061: syntax error : id
    entifier 'CRITICAL_SECTION'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(318) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(319) : error C2061: syntax error : id
    entifier 'PCRITICAL_SECTION'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(319) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(320) : error C2061: syntax error : id
    entifier 'LPCRITICAL_SECTION'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(320) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(322) : error C2061: syntax error : id
    entifier 'CRITICAL_SECTION_DEBUG'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(322) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(323) : error C2061: syntax error : id
    entifier 'PCRITICAL_SECTION_DEBUG'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(323) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(324) : error C2061: syntax error : id
    entifier 'LPCRITICAL_SECTION_DEBUG'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(324) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(332) : error C2061: syntax error : id
    entifier 'INIT_ONCE'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(332) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(333) : error C2061: syntax error : id
    entifier 'PINIT_ONCE'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(333) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(334) : error C2061: syntax error : id
    entifier 'LPINIT_ONCE'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(334) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(363) : error C2146: syntax error : mi
    ssing ')' before identifier 'InitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(363) : error C2061: syntax error : id
    entifier 'InitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(363) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(363) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(366) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(372) : error C2146: syntax error : mi
    ssing ')' before identifier 'InitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(372) : error C2061: syntax error : id
    entifier 'InitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(372) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(373) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(379) : error C2146: syntax error : mi
    ssing ')' before identifier 'InitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(379) : error C2061: syntax error : id
    entifier 'InitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(379) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(379) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(383) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(389) : error C2146: syntax error : mi
    ssing ')' before identifier 'lpInitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(389) : error C2061: syntax error : id
    entifier 'lpInitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(389) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(389) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(393) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(399) : error C2146: syntax error : mi
    ssing ')' before identifier 'lpInitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(399) : error C2061: syntax error : id
    entifier 'lpInitOnce'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(399) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(399) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(402) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(410) : error C2061: syntax error : id
    entifier 'SRWLOCK'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(410) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(410) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(418) : error C2146: syntax error : mi
    ssing ')' before identifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(418) : error C2061: syntax error : id
    entifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(418) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(419) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(425) : error C2146: syntax error : mi
    ssing ')' before identifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(425) : error C2061: syntax error : id
    entifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(425) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(426) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(432) : error C2146: syntax error : mi
    ssing ')' before identifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(432) : error C2061: syntax error : id
    entifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(432) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(433) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(439) : error C2146: syntax error : mi
    ssing ')' before identifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(439) : error C2061: syntax error : id
    entifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(439) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(440) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(446) : error C2146: syntax error : mi
    ssing ')' before identifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(446) : error C2061: syntax error : id
    entifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(446) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(447) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(453) : error C2146: syntax error : mi
    ssing ')' before identifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(453) : error C2061: syntax error : id
    entifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(453) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(454) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(460) : error C2146: syntax error : mi
    ssing ')' before identifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(460) : error C2061: syntax error : id
    entifier 'SRWLock'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(460) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(461) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(467) : error C2061: syntax error : id
    entifier 'CONDITION_VARIABLE'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(467) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(467) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(473) : error C2146: syntax error : mi
    ssing ')' before identifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(473) : error C2061: syntax error : id
    entifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(473) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(474) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(480) : error C2146: syntax error : mi
    ssing ')' before identifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(480) : error C2061: syntax error : id
    entifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(480) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(481) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(487) : error C2146: syntax error : mi
    ssing ')' before identifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(487) : error C2061: syntax error : id
    entifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(487) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(488) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(494) : error C2146: syntax error : mi
    ssing ')' before identifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(494) : error C2061: syntax error : id
    entifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(494) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(494) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(497) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(503) : error C2146: syntax error : mi
    ssing ')' before identifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(503) : error C2061: syntax error : id
    entifier 'ConditionVariable'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(503) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(503) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(507) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(554) : error C2061: syntax error : id
    entifier 'LPLDT_ENTRY'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(554) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(2288) : error C2373: 'InterlockedIncr
    ement' : redefinition; different type modifiers
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(2288) : error C1003: error count exce
    eds 100; stopping compilation
    Linking Executable - objchk_win7_x86\i386\driver.sys
    1>link : error LNK1181: cannot open input file 'c:\simple_driver\driver\driver\o
    bjchk_win7_x86\i386\code.obj'
    BUILD: Finish time: Thu Jun 20 01:27:15 2013
    BUILD: Done
    
        3 files compiled - 4 Warnings - 102 Errors - 173 LPS
        1 executable built - 1 Error


    Wednesday, June 19, 2013 8:00 PM
  • Change:

    #include <wdm.h>
    #include <windef.h>
    #include <ntddk.h>
    #include <Ntifs.h>
    #include <fltkernel.h>

    to


    #include <Ntifs.h>
    #include <fltkernel.h>

    wdm and ntddk are included in ntifs.h  and windef.h is a user space include you can't use in the kernel.



    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Wednesday, June 19, 2013 8:56 PM
  • C:\simple_driver\driver\driver>build -cefbw
    path contains nonexistant d:\embarcadero\rad studio\9.0\bin, removing
    path contains nonexistant c:\users\public\documents\rad studio\9.0\bpl, removing
    
    path contains nonexistant d:\embarcadero\rad studio\9.0\bin64, removing
    path contains nonexistant c:\users\public\documents\rad studio\9.0\bpl\win64, re
    moving
    BUILD: Compile and Link for x86
    BUILD: Loading c:\winddk\7600.16385.1\build.dat...
    BUILD: Computing Include file dependencies:
    BUILD: Start time: Thu Jun 20 03:40:02 2013
    BUILD: Examining c:\simple_driver\driver\driver directory for files to compile.
        c:\simple_driver\driver\driver Invalidating OACR warning log for 'root:x86fr
    e'
    BUILD: Saving c:\winddk\7600.16385.1\build.dat...
    BUILD: Compiling and Linking c:\simple_driver\driver\driver directory
    Configuring OACR for 'root:x86fre' - <OACR on>
    Compiling - code.c
    1>errors in directory c:\simple_driver\driver\driver
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(247) : error C2016: C requires that a
     struct or union has at least one member
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(247) : error C2061: syntax error : id
    entifier 'DWORD'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(248) : error C2061: syntax error : id
    entifier 'OffsetHigh'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(248) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(249) : error C2059: syntax error : '}
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(251) : error C2059: syntax error : '}
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(254) : error C2059: syntax error : '}
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(258) : error C2061: syntax error : id
    entifier 'LPOVERLAPPED'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(259) : error C2365: 'Internal' : rede
    finition; previous definition was 'enumerator'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(260) : error C2061: syntax error : id
    entifier 'dwNumberOfBytesTransferred'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(260) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(261) : error C2059: syntax error : '}
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(264) : error C2016: C requires that a
     struct or union has at least one member
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(264) : error C2061: syntax error : id
    entifier 'DWORD'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(265) : error C2061: syntax error : id
    entifier 'lpSecurityDescriptor'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(265) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(266) : error C2061: syntax error : id
    entifier 'bInheritHandle'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(266) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(267) : error C2059: syntax error : '}
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(272) : error C2061: syntax error : id
    entifier 'DWORD'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(273) : error C2061: syntax error : id
    entifier 'dwThreadId'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(273) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(274) : error C2059: syntax error : '}
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(284) : error C2016: C requires that a
     struct or union has at least one member
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(284) : error C2061: syntax error : id
    entifier 'DWORD'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(285) : error C2061: syntax error : id
    entifier 'dwHighDateTime'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(285) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(286) : error C2059: syntax error : '}
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(295) : error C2016: C requires that a
     struct or union has at least one member
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(295) : error C2061: syntax error : id
    entifier 'WORD'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(296) : error C2061: syntax error : id
    entifier 'wMonth'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(296) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(297) : error C2061: syntax error : id
    entifier 'wDayOfWeek'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(297) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(298) : error C2061: syntax error : id
    entifier 'wDay'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(298) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(299) : error C2061: syntax error : id
    entifier 'wHour'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(299) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(300) : error C2061: syntax error : id
    entifier 'wMinute'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(300) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(301) : error C2061: syntax error : id
    entifier 'wSecond'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(301) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(302) : error C2061: syntax error : id
    entifier 'wMilliseconds'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(302) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(303) : error C2059: syntax error : '}
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(306) : error C2143: syntax error : mi
    ssing ')' before '*'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(306) : error C2143: syntax error : mi
    ssing '{' before '*'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(306) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(307) : error C2146: syntax error : mi
    ssing ')' before identifier 'lpThreadParameter'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(307) : error C2061: syntax error : id
    entifier 'lpThreadParameter'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(307) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(308) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(309) : error C2061: syntax error : id
    entifier 'LPTHREAD_START_ROUTINE'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(309) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(312) : error C2143: syntax error : mi
    ssing ')' before '*'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(312) : error C2143: syntax error : mi
    ssing '{' before '*'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(312) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(313) : error C2146: syntax error : mi
    ssing ')' before identifier 'lpFiberParameter'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(313) : error C2061: syntax error : id
    entifier 'lpFiberParameter'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(313) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(314) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(315) : error C2061: syntax error : id
    entifier 'LPFIBER_START_ROUTINE'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(315) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(318) : error C2061: syntax error : id
    entifier 'CRITICAL_SECTION'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(318) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(319) : error C2061: syntax error : id
    entifier 'PCRITICAL_SECTION'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(319) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(320) : error C2061: syntax error : id
    entifier 'LPCRITICAL_SECTION'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(320) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(322) : error C2061: syntax error : id
    entifier 'CRITICAL_SECTION_DEBUG'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(322) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(323) : error C2061: syntax error : id
    entifier 'PCRITICAL_SECTION_DEBUG'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(323) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(324) : error C2061: syntax error : id
    entifier 'LPCRITICAL_SECTION_DEBUG'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(324) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(362) : error C2143: syntax error : mi
    ssing ')' before '*'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(362) : error C2143: syntax error : mi
    ssing '{' before '*'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(362) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(371) : error C2061: syntax error : id
    entifier 'InitOnceInitialize'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(371) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(372) : error C2059: syntax error : 't
    ype'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(377) : error C2061: syntax error : id
    entifier 'WINAPI'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(377) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(380) : error C2146: syntax error : mi
    ssing ')' before identifier 'InitFn'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(380) : error C2081: 'PINIT_ONCE_FN' :
     name in formal parameter list illegal
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(380) : error C2061: syntax error : id
    entifier 'InitFn'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(380) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(380) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(383) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(387) : error C2061: syntax error : id
    entifier 'WINAPI'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(387) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(390) : error C2146: syntax error : mi
    ssing ')' before identifier 'dwFlags'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(390) : error C2081: 'DWORD' : name in
     formal parameter list illegal
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(390) : error C2061: syntax error : id
    entifier 'dwFlags'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(390) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(390) : error C2059: syntax error : ',
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(393) : error C2059: syntax error : ')
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(397) : error C2061: syntax error : id
    entifier 'WINAPI'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(397) : error C2059: syntax error : ';
    '
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(400) : error C2146: syntax error : mi
    ssing ')' before identifier 'dwFlags'
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(400) : error C2081: 'DWORD' : name in
     formal parameter list illegal
    1>c:\winddk\7600.16385.1\inc\api\winbase.h(400) : error C1003: error count excee
    ds 100; stopping compilation
    Linking Executable - objfre_win7_x86\i386\driver.sys
    1>link : error LNK1181: cannot open input file 'c:\simple_driver\driver\driver\o
    bjfre_win7_x86\i386\code.obj'
    BUILD: Finish time: Thu Jun 20 03:40:04 2013
    BUILD: Done
    
        3 files compiled - 4 Warnings - 102 Errors
        1 executable built - 1 Error
    errors did change ... still lost 
    Wednesday, June 19, 2013 10:13 PM
  • You can't include winbase.h or any other user space (i.e. from the API directory) include file.   Take a sources file from a simple WDK project, change the name to the file you showed as your code and retry this.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Wednesday, June 19, 2013 11:08 PM
  • i narrowed it down ... everything works well till i add the "ntifs.h" header to use `FILE_BOTH_DIRECTORY_INFORMATION` and `ZwQueryDirectoryFile` ...
    Wednesday, June 19, 2013 11:16 PM