Author: janderwald
Date: Mon Sep 14 00:13:48 2009
New Revision: 43044
URL: 
http://svn.reactos.org/svn/reactos?rev=43044&view=rev
Log:
- Add back PHYSICAL_ADDRESS workarround for IDmaChannel::PhysicalAddress
- Only define guids for gcc
- Add missing PURE interface function definitions
- Silence debug spam
- Initialize ResourceList members
- Fix calculation when allocating new resources entries
- Fix building of portcls with msvc
Modified:
    trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_slave.cpp
    trunk/reactos/drivers/wdm/audio/backpln/portcls/guids.cpp
    trunk/reactos/drivers/wdm/audio/backpln/portcls/interfaces.hpp
    trunk/reactos/drivers/wdm/audio/backpln/portcls/portcls.rbuild
    trunk/reactos/drivers/wdm/audio/backpln/portcls/private.hpp
    trunk/reactos/drivers/wdm/audio/backpln/portcls/resource.cpp
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_slave.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_slave.cpp [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_slave.cpp [iso-8859-1] Mon Sep 14
00:13:48 2009
@@ -196,11 +196,16 @@
 PHYSICAL_ADDRESS
 NTAPI
-CDmaChannelInit::PhysicalAddress()
+CDmaChannelInit::PhysicalAddress(
+    PPHYSICAL_ADDRESS Address)
 {
     DPRINT("CDmaChannelInit_PhysicalAdress: this %p Virtuell %p Physical High %x Low
%x%\n", this, m_Buffer, m_Address.HighPart, m_Address.LowPart);
-    return m_Address;
+    PHYSICAL_ADDRESS Result;
+
+    Address->QuadPart = m_Address.QuadPart;
+    Result.QuadPart = (PtrToUlong(Address));
+    return Result;
 }
 VOID
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/guids.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/guids.cpp [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/guids.cpp [iso-8859-1] Mon Sep 14
00:13:48 2009
@@ -6,9 +6,12 @@
  * PROGRAMMER:      Johannes Anderwald
  */
-
+#ifdef _MSC_VER
+#define PUT_GUIDS_HERE
+#endif
 #include "private.hpp"
+#ifndef _MSC_VER
 const GUID CLSID_PortTopology = {0xb4c90a32L, 0x5791, 0x11d0, {0x86, 0xf9, 0x00, 0xa0,
0xc9, 0x11, 0xb5, 0x44}};
 const GUID CLSID_PortMidi = {0xb4c90a43L, 0x5791, 0x11d0, {0x86, 0xf9, 0x00, 0xa0, 0xc9,
0x11, 0xb5, 0x44}};
 const GUID CLSID_PortWaveCyclic = {0xb4c90a2aL, 0x5791, 0x11d0, {0x86, 0xf9, 0x00, 0xa0,
0xc9, 0x11, 0xb5, 0x44}};
@@ -98,3 +101,4 @@
 const GUID IID_IUnregisterSubdevice              = {0x16738177, 0xe199, 0x41f9, {0x9a,
0x87, 0xab, 0xb2, 0xa5, 0x43, 0x2f, 0x21}};
 const GUID IID_IUnregisterPhysicalConnection     = {0x6c38e231, 0x2a0d, 0x428d, {0x81,
0xf8, 0x07, 0xcc, 0x42, 0x8b, 0xb9, 0xa4}};
+#endif
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/interfaces.hpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/interfaces.hpp [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/interfaces.hpp [iso-8859-1] Mon Sep 14
00:13:48 2009
@@ -304,46 +304,46 @@
         IN PDEVICE_OBJECT DeviceObject,
         IN ULONG FrameSize,
         IN ULONG Alignment,
-        IN PVOID SilenceBuffer);
+        IN PVOID SilenceBuffer) PURE;
     STDMETHOD_(NTSTATUS, AddMapping)(THIS_
         IN PUCHAR Buffer,
         IN ULONG BufferSize,
-        IN PIRP Irp);
+        IN PIRP Irp) PURE;
     STDMETHOD_(NTSTATUS, GetMapping)(THIS_
         OUT PUCHAR * Buffer,
-        OUT PULONG BufferSize);
+        OUT PULONG BufferSize) PURE;
     STDMETHOD_(VOID, UpdateMapping)(THIS_
-        IN ULONG BytesWritten);
-
-    STDMETHOD_(ULONG, NumMappings)(THIS);
-
-    STDMETHOD_(ULONG, NumData)(THIS);
-
-    STDMETHOD_(BOOL, MinimumDataAvailable)(THIS);
-
-    STDMETHOD_(BOOL, CancelBuffers)(THIS);
+        IN ULONG BytesWritten) PURE;
+
+    STDMETHOD_(ULONG, NumMappings)(THIS) PURE;
+
+    STDMETHOD_(ULONG, NumData)(THIS) PURE;
+
+    STDMETHOD_(BOOL, MinimumDataAvailable)(THIS) PURE;
+
+    STDMETHOD_(BOOL, CancelBuffers)(THIS) PURE;
     STDMETHOD_(VOID, UpdateFormat)(THIS_
-        IN PKSDATAFORMAT DataFormat);
+        IN PKSDATAFORMAT DataFormat) PURE;
     STDMETHOD_(NTSTATUS, GetMappingWithTag)(THIS_
         IN PVOID Tag,
         OUT PPHYSICAL_ADDRESS  PhysicalAddress,
         OUT PVOID  *VirtualAddress,
         OUT PULONG  ByteCount,
-        OUT PULONG  Flags);
+        OUT PULONG  Flags) PURE;
     STDMETHOD_(NTSTATUS, ReleaseMappingWithTag)(THIS_
-        IN PVOID Tag);
-
-    STDMETHOD_(BOOL, HasLastMappingFailed)(THIS);
-    STDMETHOD_(VOID, PrintQueueStatus)(THIS);
+        IN PVOID Tag) PURE;
+
+    STDMETHOD_(BOOL, HasLastMappingFailed)(THIS) PURE;
+    STDMETHOD_(VOID, PrintQueueStatus)(THIS) PURE;
     STDMETHOD_(VOID, SetMinimumDataThreshold)(THIS_
-        IN ULONG MinimumDataThreshold);
-    STDMETHOD_(ULONG, GetMinimumDataThreshold)(THIS);
+        IN ULONG MinimumDataThreshold) PURE;
+    STDMETHOD_(ULONG, GetMinimumDataThreshold)(THIS) PURE;
 };
@@ -633,20 +633,20 @@
         IN KSPIN_DESCRIPTOR * PinDescriptor,
         IN PDEVICE_OBJECT DeviceObject) PURE;
-    STDMETHOD_(PVOID, GetIrpStream)(THIS);
-    STDMETHOD_(PMINIPORT, GetMiniport)(THIS);
+    STDMETHOD_(PVOID, GetIrpStream)(THIS) PURE;
+    STDMETHOD_(PMINIPORT, GetMiniport)(THIS) PURE;
 };
 #define IMP_IPortPinWavePci                        \
     IMP_IIrpTarget;                                \
     STDMETHODIMP_(NTSTATUS) Init(THIS_             \
         IN PPORTWAVEPCI Port,                      \
-               IN PPORTFILTERWAVEPCI Filter,              \
+        IN PPORTFILTERWAVEPCI Filter,              \
         IN KSPIN_CONNECT * ConnectDetails,         \
         IN KSPIN_DESCRIPTOR * PinDescriptor,       \
         IN PDEVICE_OBJECT DeviceObject);           \
                                                    \
-    STDMETHODIMP_(PVOID) GetIrpStream(THIS);       \
+    STDMETHODIMP_(PVOID) GetIrpStream();           \
     STDMETHODIMP_(PMINIPORT) GetMiniport(THIS)
@@ -771,11 +771,11 @@
         IN KSPIN_CONNECT * ConnectDetails,
         IN KSPIN_DESCRIPTOR * PinDescriptor) PURE;
-    STDMETHOD_(ULONG, GetCompletedPosition)(THIS);
-    STDMETHOD_(ULONG, GetCycleCount)(THIS);
-    STDMETHOD_(ULONG, GetDeviceBufferSize)(THIS);
-    STDMETHOD_(PVOID, GetIrpStream)(THIS);
-    STDMETHOD_(PMINIPORT, GetMiniport)(THIS);
+    STDMETHOD_(ULONG, GetCompletedPosition)(THIS) PURE;
+    STDMETHOD_(ULONG, GetCycleCount)(THIS) PURE;
+    STDMETHOD_(ULONG, GetDeviceBufferSize)(THIS) PURE;
+    STDMETHOD_(PVOID, GetIrpStream)(THIS) PURE;
+    STDMETHOD_(PMINIPORT, GetMiniport)(THIS) PURE;
 };
 #define IMP_IPortPinWaveCyclic                           \
@@ -814,7 +814,7 @@
     STDMETHOD_(NTSTATUS, FreePin)(THIS_
         IN struct IPortPinDMus* Pin)PURE;
-    STDMETHOD_(VOID, NotifyPins)(THIS);
+    STDMETHOD_(VOID, NotifyPins)(THIS) PURE;
 };
 typedef IPortFilterDMus *PPORTFILTERDMUS;
@@ -848,7 +848,7 @@
         IN KSPIN_DESCRIPTOR * PinDescriptor,
         IN PDEVICE_OBJECT DeviceObject) PURE;
-    STDMETHOD_(VOID, Notify)(THIS);
+    STDMETHOD_(VOID, Notify)(THIS) PURE;
 };
 #define IMP_IPortPinDMus                       \
@@ -868,28 +868,95 @@
  *****************************************************************************
  */
+#define IMP_IDmaChannelEx                                                 \
+    STDMETHODIMP_(NTSTATUS) AllocateBuffer(                               \
+        IN  ULONG BufferSize,                                             \
+        IN  PPHYSICAL_ADDRESS PhysicalAddressConstraint OPTIONAL);        \
+                                                                          \
+    STDMETHODIMP_(void) FreeBuffer(void);                                 \
+    STDMETHODIMP_(ULONG) TransferCount(void);                             \
+    STDMETHODIMP_(ULONG) MaximumBufferSize(void);                         \
+    STDMETHODIMP_(ULONG) AllocatedBufferSize(void);                       \
+    STDMETHODIMP_(ULONG) BufferSize(void);                                \
+                                                                          \
+    STDMETHODIMP_(void) SetBufferSize(                                    \
+        IN  ULONG BufferSize);                                            \
+                                                                          \
+    STDMETHODIMP_(PVOID) SystemAddress(void);                             \
+    STDMETHODIMP_(PHYSICAL_ADDRESS) PhysicalAddress(                      \
+        IN  PPHYSICAL_ADDRESS PhysicalAddressConstraint OPTIONAL);        \
+    STDMETHODIMP_(PADAPTER_OBJECT) GetAdapterObject(void);                \
+                                                                          \
+    STDMETHODIMP_(void) CopyTo(                                           \
+        IN  PVOID Destination,                                            \
+        IN  PVOID Source,                                                 \
+        IN  ULONG ByteCount);                                             \
+                                                                          \
+    STDMETHODIMP_(void) CopyFrom(                                         \
+        IN  PVOID Destination,                                            \
+        IN  PVOID Source,                                                 \
+        IN  ULONG ByteCount)
+
+#define IMP_IDmaChannelSlaveEx                 \
+    IMP_IDmaChannelEx;                         \
+    STDMETHODIMP_(NTSTATUS) Start(             \
+        IN  ULONG MapSize,                     \
+        IN  BOOLEAN WriteToDevice);            \
+                                               \
+    STDMETHODIMP_(NTSTATUS) Stop(void);        \
+    STDMETHODIMP_(ULONG) ReadCounter(void);    \
+                                               \
+    STDMETHODIMP_(NTSTATUS) WaitForTC(         \
+        ULONG Timeout)
+
+#define IMP_IDmaChannelInit\
+    IMP_IDmaChannelSlaveEx;\
+    STDMETHODIMP_(NTSTATUS) Init( \
+        IN  PDEVICE_DESCRIPTION DeviceDescription, \
+        IN  PDEVICE_OBJECT DeviceObject)
+
+#define DEFINE_ABSTRACT_DMACHANNEL_EX() \
+    STDMETHOD_(NTSTATUS, AllocateBuffer)( THIS_ \
+        IN  ULONG BufferSize, \
+        IN  PPHYSICAL_ADDRESS PhysicalAddressConstraint OPTIONAL) PURE; \
+\
+    STDMETHOD_(void, FreeBuffer)( THIS ) PURE; \
+    STDMETHOD_(ULONG, TransferCount)( THIS ) PURE; \
+    STDMETHOD_(ULONG, MaximumBufferSize)( THIS ) PURE; \
+    STDMETHOD_(ULONG, AllocatedBufferSize)( THIS ) PURE; \
+    STDMETHOD_(ULONG, BufferSize)( THIS ) PURE; \
+\
+    STDMETHOD_(void, SetBufferSize)( THIS_ \
+        IN  ULONG BufferSize) PURE; \
+\
+    STDMETHOD_(PVOID, SystemAddress)( THIS ) PURE; \
+    STDMETHOD_(PHYSICAL_ADDRESS, PhysicalAddress)( THIS_       \
+        IN PPHYSICAL_ADDRESS Address) PURE; \
+    STDMETHOD_(PADAPTER_OBJECT, GetAdapterObject)( THIS ) PURE; \
+\
+    STDMETHOD_(void, CopyTo)( THIS_ \
+        IN  PVOID Destination, \
+        IN  PVOID Source, \
+        IN  ULONG ByteCount) PURE; \
+\
+    STDMETHOD_(void, CopyFrom)( THIS_ \
+        IN  PVOID Destination, \
+        IN  PVOID Source, \
+        IN  ULONG ByteCount) PURE;
+
 #undef INTERFACE
 #define INTERFACE IDmaChannelInit
 DECLARE_INTERFACE_(IDmaChannelInit, IUnknown)
 {
     DEFINE_ABSTRACT_UNKNOWN()
-    DEFINE_ABSTRACT_DMACHANNEL()
+    DEFINE_ABSTRACT_DMACHANNEL_EX()
     DEFINE_ABSTRACT_DMACHANNELSLAVE()
     STDMETHOD_(NTSTATUS, Init)( THIS_
         IN PDEVICE_DESCRIPTION DeviceDescription,
         IN PDEVICE_OBJECT DeviceObject) PURE;
 };
-
-
-
-#define IMP_IDmaChannelInit\
-    IMP_IDmaChannelSlave;\
-    STDMETHODIMP_(NTSTATUS) Init( \
-        IN  PDEVICE_DESCRIPTION DeviceDescription, \
-        IN  PDEVICE_OBJECT DeviceObject)
-
 #undef INTERFACE
@@ -1021,7 +1088,4 @@
         IN      ULONG             Index                                   \
     )
-
-
-
 #endif
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/portcls.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/portcls.rbuild [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/portcls.rbuild [iso-8859-1] Mon Sep 14
00:13:48 2009
@@ -15,6 +15,10 @@
        <group compilerset="gcc">
                <compilerflag
compiler="cxx">-fno-exceptions</compilerflag>
                <compilerflag
compiler="cxx">-fno-rtti</compilerflag>
+       </group>
+
+       <group compilerset="msc">
+               <compilerflag compiler="cxx">/GR-</compilerflag>
        </group>
        <file>adapter.cpp</file>
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/private.hpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/private.hpp [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/private.hpp [iso-8859-1] Mon Sep 14
00:13:48 2009
@@ -12,7 +12,7 @@
 #include <ntddk.h>
 #include <portcls.h>
-#define YDEBUG
+#define NDEBUG
 #include <debug.h>
 #include <dmusicks.h>
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/resource.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/resource.cpp [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/resource.cpp [iso-8859-1] Mon Sep 14
00:13:48 2009
@@ -34,7 +34,7 @@
     }
     IMP_IResourceList;
-    CResourceList(IUnknown * OuterUnknown) {}
+    CResourceList(IUnknown * OuterUnknown) : m_OuterUnknown(OuterUnknown),
m_PoolType(NonPagedPool), m_TranslatedResourceList(0), m_UntranslatedResourceList(0),
m_NumberOfEntries(0) {}
     virtual ~CResourceList() {}
 public:
@@ -88,7 +88,7 @@
     IN  CM_RESOURCE_TYPE Type)
 {
     ULONG Index, Count = 0;
-    PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
+    PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor, UnPartialDescriptor;
     PC_ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
@@ -97,17 +97,30 @@
         // no resource list
         return 0;
     }
-
+     PC_ASSERT(m_TranslatedResourceList->List[0].PartialResourceList.Count ==
m_UntranslatedResourceList->List[0].PartialResourceList.Count);
     // I guess the translated and untranslated lists will be same length?
     for (Index = 0; Index <
m_TranslatedResourceList->List[0].PartialResourceList.Count; Index ++ )
     {
         PartialDescriptor =
&m_TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[Index];
-        DPRINT("Descriptor Type %u\n", PartialDescriptor->Type);
+        UnPartialDescriptor =
&m_UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[Index];
+        DPRINT1("Descriptor Type %u\n", PartialDescriptor->Type);
         if (PartialDescriptor->Type == Type)
         {
             // Yay! Finally found one that matches!
             Count++;
         }
+
+        if (PartialDescriptor->Type == CmResourceTypeInterrupt)
+        {
+            DPRINT1("Index %u TRANS   Interrupt Number Affinity %x Level %u Vector
%u\n", Index, PartialDescriptor->u.Interrupt.Affinity,
PartialDescriptor->u.Interrupt.Level, PartialDescriptor->u.Interrupt.Vector,
PartialDescriptor->u.Port.Start.LowPart, PartialDescriptor->Flags);
+            DPRINT1("Index %u UNTRANS Interrupt Number Affinity %x Level %u Vector
%u\n", Index, UnPartialDescriptor->u.Interrupt.Affinity,
UnPartialDescriptor->u.Interrupt.Level, UnPartialDescriptor->u.Interrupt.Vector,
PartialDescriptor->u.Port.Start.LowPart, PartialDescriptor->Flags);
+
+        }
+               else if (PartialDescriptor->Type == CmResourceTypePort)
+               {
+            DPRINT1("Index %u TRANS    Port Length %u Start %u %u Flags %x\n",
Index, PartialDescriptor->u.Port.Length, PartialDescriptor->u.Port.Start.HighPart,
PartialDescriptor->u.Port.Start.LowPart, PartialDescriptor->Flags);
+            DPRINT1("Index %u UNTRANS  Port Length %u Start %u %u Flags %x\n",
Index, UnPartialDescriptor->u.Port.Length,
UnPartialDescriptor->u.Port.Start.HighPart,
UnPartialDescriptor->u.Port.Start.LowPart, UnPartialDescriptor->Flags);
+               }
     }
     DPRINT("Found %d type %d\n", Count, Type);
@@ -200,9 +213,8 @@
     NewTranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount+1]);
     TranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
 #else
-    NewTranslatedSize = sizeof(CM_RESOURCE_LIST) + (ResourceCount > 0 ?
(ResourceCount+1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) : 0);
-    TranslatedSize = sizeof(CM_RESOURCE_LIST) + (ResourceCount > 0 ? (ResourceCount) *
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) : 0);
-
+    NewTranslatedSize = sizeof(CM_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)
+ (ResourceCount+1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
+    TranslatedSize = sizeof(CM_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) +
(ResourceCount) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
 #endif
     NewTranslatedResources = (PCM_RESOURCE_LIST)AllocateItem(m_PoolType,
NewTranslatedSize, TAG_PORTCLASS);
     if (!NewTranslatedResources)
@@ -216,9 +228,8 @@
     NewUntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount+1]);
     UntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
 #else
-    NewUntranslatedSize = sizeof(CM_RESOURCE_LIST) + (ResourceCount > 0 ?
(ResourceCount+1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) : 0);
-    UntranslatedSize = sizeof(CM_RESOURCE_LIST) + (ResourceCount > 0 ? (ResourceCount)
* sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) : 0);
-
+    NewUntranslatedSize = sizeof(CM_RESOURCE_LIST) -
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + (ResourceCount+1) *
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
+    UntranslatedSize = sizeof(CM_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)
+ (ResourceCount) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
 #endif
@@ -361,7 +372,7 @@
 #ifdef _MSC_VER
     NewTranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
 #else
-    NewTranslatedSize = sizeof(CM_RESOURCE_LIST) + (ResourceCount > 0 ?
(ResourceCount-1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) : 0);
+    NewTranslatedSize = sizeof(CM_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)
+ (ResourceCount) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
 #endif
     // store resource count
@@ -372,7 +383,7 @@
 #ifdef _MSC_VER
     NewUntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
 #else
-    NewUntranslatedSize = sizeof(CM_RESOURCE_LIST) + (ResourceCount > 0 ?
(ResourceCount-1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) : 0);
+    NewUntranslatedSize = sizeof(CM_RESOURCE_LIST) -
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + (ResourceCount) *
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
 #endif
     // allocate translated resource list
@@ -454,6 +465,7 @@
     NewList->m_OuterUnknown = OuterUnknown;
     NewList->m_PoolType = PoolType;
     NewList->m_Ref = 1;
+    NewList->m_NumberOfEntries = 0;
     *OutResourceList = (IResourceList*)NewList;