FIX: MIDL compiler structure packing problems (136500)
The information in this article applies to:
- Microsoft Win32 Software Development Kit (SDK) 3.1
- Microsoft Win32 Software Development Kit (SDK) 3.5
- Microsoft Win32 Software Development Kit (SDK) 3.51
- Microsoft Win32 Software Development Kit (SDK) 4.0
This article was previously published under Q136500 SYMPTOMS
An RPC application that uses stub code generated by MIDL throws memory
exceptions, causes a general protection (GP) fault, or overwrites memory in
the data heap. The RPC application is using a structure or union in the IDL
file.
CAUSE
The /Zp (packing) option of the MIDL compiler does not affect the size of
the structure; MIDL always uses a packing of 1. However, the /Zp option of
the C compiler does increase the size of the structure. Because MIDL
assumes a packing of one, it generates code that allocates less memory
than what is actually needed.
You can verify the behavior of the MIDL compiler by searching your client
stub code for _StubMsg.pfnAllocate. This call is present only with semi-
interpreted stubs (the default MIDL option, /Os). Try compiling your IDL
file with different /Zp settings, and notice that the memory allocated by
_StubMsg.pfnAllocate is unchanged, though it should change to accommodate
packing space.
RESOLUTION
There are three solutions to correct this problem:
- Use MIDL's /Oi option.
-or-
- Use #pragma pack(1) in the stub code to use a packing of 1.
-or-
- Pad your interface declaration to match the padding done by the C
compiler.
Please see MORE INFORMATION for details.
STATUS
Microsoft has confirmed this to be a problem in MIDL 2.00.0102 for the
Win32 SDK. This problem was corrected in MIDL 3.0 (shipped with
Windows NT 4.0 beta SDK) and was corrected in Microsoft Windows 2000.
Modification Type: | Major | Last Reviewed: | 10/16/2002 |
---|
Keywords: | kbAPI kbBug kbnetwork kbOSWin2000fix kbRPC KB136500 |
---|
|