Use W32API/PSDK structures/constants. The whole /ldr code is in MAJOR need of re-writing. Amazing it even works.
Modified: trunk/reactos/include/pe.h
Modified: trunk/reactos/ntoskrnl/ldr/loader.c

Modified: trunk/reactos/include/pe.h
--- trunk/reactos/include/pe.h	2005-01-01 20:44:34 UTC (rev 12708)
+++ trunk/reactos/include/pe.h	2005-01-01 22:10:23 UTC (rev 12709)
@@ -379,10 +379,10 @@
 	} u1;
 } IMAGE_THUNK_DATA,*PIMAGE_THUNK_DATA;
 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
-	_ANONYMOUS_UNION union {
+	union {
 		DWORD Characteristics;
 		PIMAGE_THUNK_DATA OriginalFirstThunk;
-	} DUMMYUNIONNAME;
+	} ;
 	DWORD TimeDateStamp;
 	DWORD ForwarderChain;
 	DWORD Name;
@@ -635,6 +635,8 @@
 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
 #define SIZEOF_RFPO_DATA 16
 #define IMAGE_FIRST_SECTION(h) ((PIMAGE_SECTION_HEADER) ((DWORD)h+FIELD_OFFSET(IMAGE_NT_HEADERS,OptionalHeader)+((PIMAGE_NT_HEADERS)(h))->FileHeader.SizeOfOptionalHeader))
+/* Temporarily adding this here. This file will die soon. */
+#define IMAGE_SCN_TYPE_NOLOAD 0x2L
 #define IMAGE_SCN_TYPE_NO_PAD 8
 #define IMAGE_SCN_CNT_CODE 32
 #define IMAGE_SCN_CNT_INITIALIZED_DATA 64

Modified: trunk/reactos/ntoskrnl/ldr/loader.c
--- trunk/reactos/ntoskrnl/ldr/loader.c	2005-01-01 20:44:34 UTC (rev 12708)
+++ trunk/reactos/ntoskrnl/ldr/loader.c	2005-01-01 22:10:23 UTC (rev 12709)
@@ -428,7 +428,7 @@
 
   /*  If MZ header exists  */
   PEDosHeader = (PIMAGE_DOS_HEADER) ModuleLoadBase;
-  if (PEDosHeader->e_magic == IMAGE_DOS_MAGIC && PEDosHeader->e_lfanew != 0L)
+  if (PEDosHeader->e_magic == IMAGE_DOS_SIGNATURE && PEDosHeader->e_lfanew != 0L)
     {
       return LdrPEProcessModule(ModuleLoadBase,
 				ModuleName,
@@ -669,18 +669,18 @@
    for (Idx = 0; Idx < PEFileHeader->NumberOfSections && (!Write || !Execute); Idx++)
    {
       Characteristics = PESectionHeaders[Idx].Characteristics;
-      if (!(Characteristics & IMAGE_SECTION_NOLOAD))
+      if (!(Characteristics & IMAGE_SCN_TYPE_NOLOAD))
       {
          Length = max(PESectionHeaders[Idx].Misc.VirtualSize, PESectionHeaders[Idx].SizeOfRawData);
          BaseAddress = PESectionHeaders[Idx].VirtualAddress + (char*)DriverBase;
          if (BaseAddress < (PVOID)((ULONG_PTR)PageStart + PAGE_SIZE) &&
              PageStart < (PVOID)((ULONG_PTR)BaseAddress + Length))
          {
-            if (Characteristics & IMAGE_SECTION_CHAR_CODE)
+            if (Characteristics & IMAGE_SCN_CNT_CODE)
 	    {
 	       Execute = TRUE;
 	    }
-	    if (Characteristics & (IMAGE_SECTION_CHAR_WRITABLE|IMAGE_SECTION_CHAR_BSS))
+	    if (Characteristics & (IMAGE_SCN_MEM_WRITE|IMAGE_SCN_LNK_OTHER))
 	    {
 	       Write = TRUE;
 	    }
@@ -730,7 +730,7 @@
   CHECKPOINT;
 
   /*  Check file magic numbers  */
-  if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC)
+  if (PEDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
     {
       CPRINT("Incorrect MZ magic: %04x\n", PEDosHeader->e_magic);
       return STATUS_UNSUCCESSFUL;
@@ -740,7 +740,7 @@
       CPRINT("Invalid lfanew offset: %08x\n", PEDosHeader->e_lfanew);
       return STATUS_UNSUCCESSFUL;
     }
-  if (PENtHeaders->Signature != IMAGE_PE_MAGIC)
+  if (PENtHeaders->Signature != IMAGE_NT_SIGNATURE)
     {
       CPRINT("Incorrect PE magic: %08x\n", PENtHeaders->Signature);
       return STATUS_UNSUCCESSFUL;
@@ -766,7 +766,7 @@
   DriverSize = 0;
   for (Idx = 0; Idx < PENtHeaders->FileHeader.NumberOfSections; Idx++)
   {
-     if (!(PESectionHeaders[Idx].Characteristics & IMAGE_SECTION_NOLOAD))
+     if (!(PESectionHeaders[Idx].Characteristics & IMAGE_SCN_TYPE_NOLOAD))
      {
         CurrentSize = PESectionHeaders[Idx].VirtualAddress + PESectionHeaders[Idx].Misc.VirtualSize;
 	DriverSize = max(DriverSize, CurrentSize);
@@ -899,9 +899,9 @@
         MmSetPageProtect(NULL, PageAddress, Protect);
      }
      
-     if (Characteristics & IMAGE_SECTION_CHAR_CODE)
+     if (Characteristics & IMAGE_SCN_CNT_CODE)
      {
-        if (Characteristics & IMAGE_SECTION_CHAR_WRITABLE)
+        if (Characteristics & IMAGE_SCN_MEM_WRITE)
 	{
 	   Protect = PAGE_EXECUTE_READWRITE;
 	}
@@ -910,7 +910,7 @@
 	   Protect = PAGE_EXECUTE_READ;
 	}
      }
-     else if (Characteristics & (IMAGE_SECTION_CHAR_WRITABLE|IMAGE_SECTION_CHAR_BSS))
+     else if (Characteristics & (IMAGE_SCN_MEM_WRITE|IMAGE_SCN_LNK_OTHER))
      {
         Protect = PAGE_READWRITE;
      }
@@ -996,7 +996,7 @@
   CHECKPOINT;
 
   /*  Check file magic numbers  */
-  if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC)
+  if (PEDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
     {
       return NULL;
     }
@@ -1004,7 +1004,7 @@
     {
       return NULL;
     }
-  if (PENtHeaders->Signature != IMAGE_PE_MAGIC)
+  if (PENtHeaders->Signature != IMAGE_NT_SIGNATURE)
     {
       return NULL;
     }
@@ -1090,9 +1090,9 @@
      BaseAddress = PESectionHeaders[Idx].VirtualAddress + (char*)DriverBase;
      PageAddress = (PVOID)PAGE_ROUND_DOWN(BaseAddress);
 
-     if (Characteristics & IMAGE_SECTION_CHAR_EXECUTABLE)
+     if (Characteristics & IMAGE_SCN_MEM_EXECUTE)
      {
-        if (Characteristics & IMAGE_SECTION_CHAR_WRITABLE)
+        if (Characteristics & IMAGE_SCN_MEM_WRITE)
 	{
 	   Protect = PAGE_EXECUTE_READWRITE;
 	}
@@ -1101,7 +1101,7 @@
 	   Protect = PAGE_EXECUTE_READ;
 	}
      }
-     else if (Characteristics & IMAGE_SECTION_CHAR_WRITABLE)
+     else if (Characteristics & IMAGE_SCN_MEM_WRITE)
      {
         Protect = PAGE_READWRITE;
      }
@@ -1115,7 +1115,7 @@
 	PageAddress = (PVOID)((ULONG_PTR)PageAddress + PAGE_SIZE);
      }
      if (DriverBase == ModuleLoadBase &&
-	 Characteristics & IMAGE_SECTION_CHAR_BSS)
+	 Characteristics & IMAGE_SCN_LNK_OTHER)
      {
         /* For ntoskrnl, we must stop after the bss section */
 	break;
@@ -1516,28 +1516,28 @@
 static NTSTATUS
 LdrPEProcessImportDirectoryEntry(PVOID DriverBase,
 			         PMODULE_OBJECT ImportedModule,
-                                 PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory)
+                                 PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory)
 {
    PVOID* ImportAddressList;
    PULONG FunctionNameList;
    ULONG Ordinal;
 
-   if (ImportModuleDirectory == NULL || ImportModuleDirectory->dwRVAModuleName == 0)
+   if (ImportModuleDirectory == NULL || ImportModuleDirectory->Name == 0)
      {
        return STATUS_UNSUCCESSFUL;
      }
 
    /* Get the import address list. */
-   ImportAddressList = (PVOID*)(DriverBase + ImportModuleDirectory->dwRVAFunctionAddressList);
+   ImportAddressList = (PVOID*)(DriverBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
 
    /* Get the list of functions to import. */
-   if (ImportModuleDirectory->dwRVAFunctionNameList != 0)
+   if (ImportModuleDirectory->OriginalFirstThunk != 0)
      {
-       FunctionNameList = (PULONG) (DriverBase + ImportModuleDirectory->dwRVAFunctionNameList);
+       FunctionNameList = (PULONG) (DriverBase + (ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk);
      }
    else
      {
-       FunctionNameList = (PULONG)(DriverBase + ImportModuleDirectory->dwRVAFunctionAddressList);
+       FunctionNameList = (PULONG)(DriverBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
      }
 
    /* Walk through function list and fixup addresses. */
@@ -1573,22 +1573,22 @@
 static NTSTATUS
 LdrPEFixupImports(PMODULE_OBJECT Module)
 {
-   PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory;
+   PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory;
    PCHAR ImportedName;
    PMODULE_OBJECT ImportedModule;
    NTSTATUS Status;
 
    /*  Process each import module  */
-   ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
+   ImportModuleDirectory = (PIMAGE_IMPORT_DESCRIPTOR)
                               RtlImageDirectoryEntryToData(Module->Base,
                                                            TRUE,
                                                            IMAGE_DIRECTORY_ENTRY_IMPORT,
                                                            NULL);
    DPRINT("Processeing import directory at %p\n", ImportModuleDirectory);
-   while (ImportModuleDirectory->dwRVAModuleName)
+   while (ImportModuleDirectory->Name)
    {
       /*  Check to make sure that import lib is kernel  */
-      ImportedName = (PCHAR) Module->Base + ImportModuleDirectory->dwRVAModuleName;
+      ImportedName = (PCHAR) Module->Base + ImportModuleDirectory->Name;
 
       Status = LdrPEGetOrLoadModule(Module, ImportedName, &ImportedModule);
       if (!NT_SUCCESS(Status))